Reputation: 27996
I am working on asp.net MVC 3 application. I am facing an issue related to session expiration. When I am logged in and website is inactive for 10-15 minutes, I try to click any link, It says object reference null error. I want that when session is expired, on clicking any link, either I should be redirected to login page with error message that session expired, or popup with same message. how to implement it in asp.net MVC 3.
Regards, Asif Hameed
Upvotes: 1
Views: 1794
Reputation: 7133
There are two timeouts normally seen in a .net web app.
The first is the session timeout. It is set in the sessionState tag.
<sessionState timeout="number of minutes" ...></sessionState>
The second is the forms cookie timeout. It is set in the authentication tag.
<authentication mode="Forms">
<forms timeout="number of minutes"/>
</authentication>
It looks like your session is timing out before your forms cookie times out.
It is better to have your session last a few minutes longer than the forms authentication cookie, that way the user can log back in within a few minutes and still have their session. I've had problems, such as the one you described, with setting them to the same value.
Upvotes: 1
Reputation: 19765
I am guessing that your code grabs something from session state and then uses it without checking if it is null first.
I would suggest looking at that code, and adding the null check. if null, then redirect to the login page as you need.
Upvotes: 2