简体   繁体   中英

How I can use a Session for a long time in my ASP.NET Application

I have a ASP.NET Application where I use Sessions. In this Session I get the language for Example.

Example:

Session["language"] = language; 

And in a other Area in my Code I use then...

language = Session["language"].toString();

It works fine but the user had open the Browser about a feu Hours in the Background with the Application then the Session don't work :(

Why it doesn't work and how I can solve this Problem.

我建议你将值保存在cookie中。

You have two options either to use cookies or to increase session timeout setting.

You can increase the session timeout by increasing timeout in the web.config .

<configuration>
  <system.web>
  ...
   <sessionState timeout="90" />
  ...
 </system.web>
</configuration>

In my opinion using cookies is a better approach.

Beginners Guide To ASP NET Cookies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM