Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net sessionID changing on postbacks?

I am writing an asp.net app that stored an object in cache. When the page loads the first time, it checks the cache for the object, if it is there, it will use the object. if the object does not exist, it will re-build it and store it in cache. since multiple users can use this app at the same time, i was trying to store the object in cache with the cache key being the SessionID. Well, i noticed that when the page posts back, the sessionID changes, so I will need to use a different unique key. Any suggestions? I was thinking about using the userID of the person logged in, but that is not unique either, since you can login with the same id multiple times.

like image 840
hp. Avatar asked Feb 28 '09 02:02

hp.


People also ask

What causes SessionID to change?

Every time an Internet user visits a specific Web site, a new session ID is assigned. Closing a browser and then reopening and visiting the site again generates a new session ID.

Does SessionID change?

Per the forums I've read, session ids don't change even we refresh or reload the page. Which is correct.

Can SessionID be duplicated?

Solution 1Yes, Session. SessionId can be duplicate.

Where does ASP.NET store SessionID?

By Default Session Id is Stored in Client m/c in the form of text file.It is Called Cookie. If session is Cookie less the that is append to Url . In Cookies.


1 Answers

I think i just found my answer from MSDN (this is a change to 2.0,3.5):

"When using cookie-based session state, ASP.NET does not allocate storage for session data until the Session object is used. As a result, a new session ID is generated for each page request until the session object is accessed. If your application requires a static session ID for the entire session, you can either implement the Session_Start method in the application's Global.asax file and store data in the Session object to fix the session ID, or you can use code in another part of your application to explicitly store data in the Session object."

http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid.aspx

like image 53
hp. Avatar answered Sep 19 '22 06:09

hp.