1
votes

I have one huge doubt

Why session ID is not as same in all the webpages?

CODE:

In webpage1.aspx.cs

String sess1 = Session.SessionID.ToString();

In webpage2.aspx.cs

String sess2 = Session.SessionID.ToString();

When i load my webpage1.aspx, it shows one unique sessionID, and navigate to webpage2.aspx it shows another new unique sessionID

Both the sessionIDs (sess1, sess2) should be same, it's generating different sessionIDs.

May i why ??

and also how to maintain that sessionID in all the aspx pages

1

1 Answers

1
votes

Reason:

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.

You have to use like this Session["Id"] = 0; like this.

If you dont use it in C# code, it will be generated new on every request.

Refer SessionId