Tuesday, August 30, 2011

Session and .NET application

It seems session ID does not created until it is first used, i.e. you may get an error when you are trying to retrieve it the first time. To avoid this, you may consider to put something similar to below in your Global.asax file if you are using .NET


protected void Session_Start(object src, EventArgs e)
{
// http://stackoverflow.com/questions/904952/whats-causing-session-state-has-created-a-session-id-but-cannot-save-it-becaus
// This is needed in order to maintain a stable session id
// it seems the session only got created at its first used. The line below just does that!
string sessionId = Session.SessionID;
}

source: as stated in the comments of the codes.

No comments: