1

I have an asp.net mvc application in which I am using a session attribute:

Session["id"] = id;

My problem is the timeout of the attribute, I'd like to be unlimited until it changes to another value. Now when the timer expires (30 sec) Session["id"] takes null as value.

What is the best way to do it?

2
  • 1
    I have been under the impression that the Session timeout can be set, but not an attribute specifically Commented Jun 26, 2013 at 12:36
  • You might try to renew the session. Take a look here primaryobjects.com/2008/01/29/… Commented Jun 5, 2018 at 21:59

3 Answers 3

5

The default Session Timeout is set to 20 minutes. According to this MSDN article:

HttpSessionState.Timeout property gets and sets the amount of time, in minutes, allowed between requests before the session-state provider terminates the session.

Keep in mind that Session is not meant to be Cache! If you want to be able to define expiration policies on variables, use cache instead.

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

Comments

2

Set the timeout value in sessionState the web config. As the comments say this isn't really the best place to put this.

Comments

1

session timeout setting is for the whole session not a specific variable .

I can think of two options :

1- session timeout expiration is sliding . so to prevent it and your session variable from being expired , call session in a period of time e.g each 20 minutes (when session timeout is 30 for example ).

2- better solution is to use cookies , if information are not sensitive .

checking these links may be useful + , + , + , +

2 Comments

those links look suspicious
the problem with cookies is the browser limits them to a max size of 4kb, which is not a lot if you serialize the data into JSON format.

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.