Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Retreaving Session

Retreaving Session

Scheduled Pinned Locked Moved ASP.NET
tutorial
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Saksida Bojan

    Hi i woud like to know how to retrive a session state from a Class. Thanks in advance

    M Offline
    M Offline
    Michael Sync
    wrote on last edited by
    #2

    Console.WriteLine(Session["mysession"]); ??

    Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

    S 1 Reply Last reply
    0
    • S Saksida Bojan

      Hi i woud like to know how to retrive a session state from a Class. Thanks in advance

      A Offline
      A Offline
      Abolfazl Sheikhloo
      wrote on last edited by
      #3

      HttpContext.Current.Session

      We Can Do Anything, If We Want It

      S 1 Reply Last reply
      0
      • M Michael Sync

        Console.WriteLine(Session["mysession"]); ??

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

        S Offline
        S Offline
        Saksida Bojan
        wrote on last edited by
        #4

        Normaly This woud be ok, but I wan't to retrive session from class, that the class isn't inherited from anything. So I Can't access Session class

        M 1 Reply Last reply
        0
        • A Abolfazl Sheikhloo

          HttpContext.Current.Session

          We Can Do Anything, If We Want It

          S Offline
          S Offline
          Saksida Bojan
          wrote on last edited by
          #5

          Already tried that. Didn't help. I can't remeber the error, because currently i am not home.

          V 1 Reply Last reply
          0
          • S Saksida Bojan

            Hi i woud like to know how to retrive a session state from a Class. Thanks in advance

            V Offline
            V Offline
            Vasudevan Deepak Kumar
            wrote on last edited by
            #6

            Within the context of web application, HttpContext.Current.Session["name"]

            Vasudevan Deepak Kumar Personal Homepage Tech Gossips

            1 Reply Last reply
            0
            • S Saksida Bojan

              Normaly This woud be ok, but I wan't to retrive session from class, that the class isn't inherited from anything. So I Can't access Session class

              M Offline
              M Offline
              Michael Sync
              wrote on last edited by
              #7

              Where did you put this class? in Web Project or somewhere?? I have tried with the following code. it works.. In Default.aspx protected void Button1_Click(object sender, EventArgs e) { Session["mysession"] = "d"; } protected void Button2_Click(object sender, EventArgs e) { Class1 obj = new Class1(); Response.Write( obj.getValueFromSession("mysession")); } In Class1.cs using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// /// Summary description for Class1 /// public class Class1 { public Class1() { // // TODO: Add constructor logic here // } public string getValueFromSession(string key) { return HttpContext.Current.Session[key].ToString(); } } it works fine.. Please try againn.

              Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

              S 2 Replies Last reply
              0
              • M Michael Sync

                Where did you put this class? in Web Project or somewhere?? I have tried with the following code. it works.. In Default.aspx protected void Button1_Click(object sender, EventArgs e) { Session["mysession"] = "d"; } protected void Button2_Click(object sender, EventArgs e) { Class1 obj = new Class1(); Response.Write( obj.getValueFromSession("mysession")); } In Class1.cs using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// /// Summary description for Class1 /// public class Class1 { public Class1() { // // TODO: Add constructor logic here // } public string getValueFromSession(string key) { return HttpContext.Current.Session[key].ToString(); } } it works fine.. Please try againn.

                Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

                S Offline
                S Offline
                Saksida Bojan
                wrote on last edited by
                #8

                Gonna try when i get home in about 6 hours

                1 Reply Last reply
                0
                • S Saksida Bojan

                  Already tried that. Didn't help. I can't remeber the error, because currently i am not home.

                  V Offline
                  V Offline
                  Vasudevan Deepak Kumar
                  wrote on last edited by
                  #9

                  If it is a compilation error, then try using System.Web.HttpContext.Current.Session["Name"] The assembly should have a reference to System.Web.

                  Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                  S 1 Reply Last reply
                  0
                  • V Vasudevan Deepak Kumar

                    If it is a compilation error, then try using System.Web.HttpContext.Current.Session["Name"] The assembly should have a reference to System.Web.

                    Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                    S Offline
                    S Offline
                    Saksida Bojan
                    wrote on last edited by
                    #10

                    Thanks, This one helps. I had compilation error saying my Session doesn't belong to HttpContext

                    1 Reply Last reply
                    0
                    • M Michael Sync

                      Where did you put this class? in Web Project or somewhere?? I have tried with the following code. it works.. In Default.aspx protected void Button1_Click(object sender, EventArgs e) { Session["mysession"] = "d"; } protected void Button2_Click(object sender, EventArgs e) { Class1 obj = new Class1(); Response.Write( obj.getValueFromSession("mysession")); } In Class1.cs using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// /// Summary description for Class1 /// public class Class1 { public Class1() { // // TODO: Add constructor logic here // } public string getValueFromSession(string key) { return HttpContext.Current.Session[key].ToString(); } } it works fine.. Please try againn.

                      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

                      S Offline
                      S Offline
                      Saksida Bojan
                      wrote on last edited by
                      #11

                      It Helped, Thanks

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups