简体   繁体   English

我如何在ASP.NET应用程序中使用Session很长时间

[英]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. 我有一个ASP.NET应用程序,我使用Sessions。 In this Session I get the language for Example. 在本课程中,我获得了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 :( 它工作正常,但用户已打开浏览器关于应用程序背景中的feu小时,然后会话不起作用:(

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. 您有两种方法可以使用cookie或增加会话超时设置。

You can increase the session timeout by increasing timeout in the web.config . 您可以通过增加web.config中的超时来增加会话超时。

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

In my opinion using cookies is a better approach. 在我看来,使用cookie是一种更好的方法。

Beginners Guide To ASP NET Cookies ASP NET Cookies初学者指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在asp.net应用程序中使用Lync api吗? - Can I use a Lync api in my asp.net application? 如何在ASP.NEt应用程序中使用来自jQuery PopUpDialog的控件 - How I can use the Controls from jquery PopUpDialog in my ASP.NEt Application 我可以使用SQL Server安全性来控制对(数据库优先)ASP.net应用程序的访问吗? 怎么样? - Can I use SQL Server security to control access to my (database first) ASP.net application? How? 如何在我的 ASP.NET Core 应用程序中使用 Startup.cs 之外的服务? - How can I use a service outside of Startup.cs in my ASP.NET Core Application? 如何在ASP.net Core应用程序中同时使用Bearer和Cookie身份验证? - How can I use both Bearer and Cookie authentication in my ASP.net Core application? 如何在 asp.net 应用程序中使用 Graphviz? - How can I use Graphviz in an asp.net application? ASP.net应用程序可以为单个请求运行多长时间 - How long can a ASP.net application run for a single request 我可以在外部 DLL 中使用 ASP.NET Session[] 变量吗 - Can I use ASP.NET Session[] variable in an external DLL 我可以在.net 4中部署我的ASP.NET MVC 4应用程序吗? - Can I deploy my ASP.NET MVC 4 application in .net 4 我如何从Session.net中的其他Web应用程序通过SessionId销毁Session? - How can I destroy Session by SessionId from different web application in asp.net?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM