0

I'm accessing the SessionID using this code in my class:

HttpContext.Current.Session.SessionID;

however I find that SessionID changes at every page postback, this happens in a short time, so the current session should not expire already. I supposed that the SessionID to remain the same for the whole time until expired.

elnath78
  • 137
  • 1
  • 13
  • Session is (usually) controlled by the presence of a cookie. If you are not logging in users then there will be a new session on each request. – Crowcoder Aug 26 '15 at 12:09
  • Does this answer your question? [Session ID changes in each Request](https://stackoverflow.com/questions/22038655/session-id-changes-in-each-request) – Mehdi Dehghani Dec 19 '19 at 13:01

2 Answers2

1

You should Use the Session_Start method in the application Global.asax file. Below Link may help you

ASP.NET: Session.SessionID changes between requests

Community
  • 1
  • 1
waris kantroo
  • 83
  • 3
  • 21
1

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.

like

protected void Session_Start(Object sender, EventArgs e) 
{
    Session["init"] = 0;
}
Amit Soni
  • 3,216
  • 6
  • 31
  • 50
  • Copied form [Session ID changes in each Request](https://stackoverflow.com/questions/22038655/session-id-changes-in-each-request) – Mehdi Dehghani Dec 19 '19 at 13:01