Click here to Skip to main content
14,664,496 members
Rate this:
Please Sign up or sign in to vote.
hello,

I have a web application created using asp.net 4.0(C#).

The session timeout for the application is default(20 mins), but for only one form i need to increase the session timeout to 2 hrs

Regards,
Varun Vimal

What I have tried:

i tried adding HttpSessionState.Timeout = 10;(10 mins for testing purpose but it gave an error) :

An object reference is required for the non-static field, method, or property 'HttpSessionState.Timeout'
Posted
Updated 2-Jun-16 21:39pm

Rate this:
Please Sign up or sign in to vote.

Solution 1

found the soultion

Session.Timeout = 10;
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Firstly, the Session shouldn't be extended - it ties up server resources, and can slow things to a crawl. That's way some hosting services reduce it from the default 20 minutes, and ignore requests to extend it!

If you are getting an "object reference is required..." error for that line, then you need to look at the variable HttpSessionState - it's value is null, and I'm not at all sure where you got it from...

Normally, the session timeout would be set in the web.config file, rather than in code: HttpSessionState.Timeout Property (System.Web.SessionState)[^] but seriously, if you need longer persistance, you should probably be lookign to not rely on teh session byut use a combination of DB and cookies for storage instead. Extending the session is not a good idea.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100