Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 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

found the soultion

C#
Session.Timeout = 10;
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900