1

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

2
  • How are you handling authentication, FormsAuthentication or something custom? Commented Nov 2, 2011 at 18:53
  • A stack trace and example code would be helpful. Commented Nov 2, 2011 at 18:54

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

>> It says object reference null error. What is it? Debug the code, I suspect n8wrl is correct. Also look at BNL's response and set you session/authentication time out correctly. I would lower them to 1,2 minutes and see if you can reproduce the problem more quickly, then understand the problem, then fix it.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.