Does ASP .NET Session reset after login?

2019-07-24 05:59发布

问题:

EDIT

This problem seems to have strangely disappeared. There must've been something funky with my environment. I'm voting to close this question.


When a user logs in, I inflate the session with a bunch of data from the Login page code-behind. Then I redirect the user to a different page in the application. I also have some session recovery logic which re-inflates the session based on the auth ticket when the user's session expires.

What seems to be happening is that I inflate the user's session with a bunch of data from the login page, then redirect them, and the request for the page to which I redirect them doesn't seem to have the session, so the application has to re-inflate it. I don't understand this - I've looked at the cookie and the session ID is not changing, and I am not resetting the session data anywhere in the code. Is this an ASP .NET 'feauture'? I'm using ASP .NET 4.0.

Edit:

To clarify: The session is inflated during the login request (on the click even of the login button). During the next request, it doesn't appear the session is populated any longer, so I end up having to re-inflate the session. Any requests that user makes after that, the session seems to "stick" and I have the properly inflated session for subsequent requests.

回答1:

To answer your question SessionState data is independent of login/logout.

There are several reasons why data might "disappear" from SessionState.

  • If you are using InProc SessionState on a web farm, the user may have a subsequent request be served by a different machine in the farm.
  • SessionState can clear if it gets too full (like a cache).
  • If you are using a custom SessionStateStoreProvider, it may not be saving/retrieving the SessionState properly.