Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

ASP.NET: Session.SessionID changes between requests

Why does the property SessionID on the Session-object in an ASP.NET-page change between requests?

I have a page like this:
...
<div>
SessionID: <%= SessionID %>
</div>
...


And the output keeps changing every time I hit F5, independent of browser.
by

2 Answers

Amit8z4mc
n my case I figured out that the session cookie had a domain that included www. prefix, while I was requesting page with no www..
Adding www. to the URL immediately fixed the problem. Later I changed cookie's domain to be set to .mysite.com instead of www.mysite.com.
sandhya6gczb
There is another, more insidious reason, why this may occur even when the Session object has been initialized as demonstrated by Cladudio.

In the Web.config, if there is an <httpCookies> entry that is set to requireSSL="true" but you are not actually using HTTPS: for a specific request, then the session cookie is not sent (or maybe not returned, I'm not sure which) which means that you end up with a brand new session for each request

Login / Signup to Answer the Question.