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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Where is the SessionID stored?

Where is the SessionID stored?

Scheduled Pinned Locked Moved ASP.NET
csharphtmlasp-netcomsysadmin
6 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.
  • J Offline
    J Offline
    John Honan
    wrote on last edited by
    #1

    I always thought the session ID was stored in a cookie on the client (when cookieless=false). To test this I wrote a very simple page to see if this was the case. I have one webpage which sets a session variable, and then I go to a second page which displays the contents of the session variable. This works as expected.

    WebForm1.aspx.vb
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    Session("UserName") = TextBox1.Text
    End Sub

    WebForm2.aspx.vb
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Response.Write("Your name is " & Session("UserName"))
    End Sub

    For the test, I manually cleared the browser cache and cookies between the page requests to try and delete the session ID. However, the session variable still displayed correctly on the second page (indicating the session ID is maintained). In fact, the only way to clear the session was to close the browser. Where is the sessionID stored on the browser? – Or am overlooking something very obvious here? (At the moment I’m thinking it’s either in the viewstate, or in the HTML header somewhere, but I still can’t work out how the browser keeps track of what the session ID is or how the server 'knows' the same session is connecting) (Using VB/ASP.NET on framework v 1.0, and IE 6.0 on XP for testing) John[^]

    H 1 Reply Last reply
    0
    • J John Honan

      I always thought the session ID was stored in a cookie on the client (when cookieless=false). To test this I wrote a very simple page to see if this was the case. I have one webpage which sets a session variable, and then I go to a second page which displays the contents of the session variable. This works as expected.

      WebForm1.aspx.vb
      Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
      Session("UserName") = TextBox1.Text
      End Sub

      WebForm2.aspx.vb
      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Response.Write("Your name is " & Session("UserName"))
      End Sub

      For the test, I manually cleared the browser cache and cookies between the page requests to try and delete the session ID. However, the session variable still displayed correctly on the second page (indicating the session ID is maintained). In fact, the only way to clear the session was to close the browser. Where is the sessionID stored on the browser? – Or am overlooking something very obvious here? (At the moment I’m thinking it’s either in the viewstate, or in the HTML header somewhere, but I still can’t work out how the browser keeps track of what the session ID is or how the server 'knows' the same session is connecting) (Using VB/ASP.NET on framework v 1.0, and IE 6.0 on XP for testing) John[^]

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      There are two types of cookies - persistent and non-persistent. Persistent cookies are stored in files - clearing your cookie cache will remove persistent cookies. Non-persistent cookies are stored in memory and aren't removed when you clear the cache. Session cookies are non-persistent.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      A X 2 Replies Last reply
      0
      • H Heath Stewart

        There are two types of cookies - persistent and non-persistent. Persistent cookies are stored in files - clearing your cookie cache will remove persistent cookies. Non-persistent cookies are stored in memory and aren't removed when you clear the cache. Session cookies are non-persistent.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Thanks Heath :-D

        J 1 Reply Last reply
        0
        • A Anonymous

          Thanks Heath :-D

          J Offline
          J Offline
          John Honan
          wrote on last edited by
          #4

          Oops! - Anonymous... :rolleyes: That's what'd happens when you clear your cache of persistent cookies... :laugh: John[^]

          H 1 Reply Last reply
          0
          • H Heath Stewart

            There are two types of cookies - persistent and non-persistent. Persistent cookies are stored in files - clearing your cookie cache will remove persistent cookies. Non-persistent cookies are stored in memory and aren't removed when you clear the cache. Session cookies are non-persistent.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            X Offline
            X Offline
            Xiangyang Liu
            wrote on last edited by
            #5

            Heath Stewart wrote: There are two types of cookies - persistent and non-persistent. Persistent cookies are stored in files - clearing your cookie cache will remove persistent cookies. Non-persistent cookies are stored in memory and aren't removed when you clear the cache. Session cookies are non-persistent. Also, a) If you set "cookieless" to be true in your web.config file, then session id will be in the url so the code will work even if you disable cookies in your browser. b) If you transfer from the first page to the second using Server.Transfer, then the second page will be displayed without communicating to your browser so no cookie will be used in this case (I thought this is true, but didn't actually test it :-O ). Click here to see my articles and software tools

            1 Reply Last reply
            0
            • J John Honan

              Oops! - Anonymous... :rolleyes: That's what'd happens when you clear your cache of persistent cookies... :laugh: John[^]

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              Lesson about persistent cookies learned, eh? :-D

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              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