简体   繁体   English

如何在asp.net mvc4中长时间保持会话超时?

[英]How to maintain session timeout for long period in asp.net mvc4?

I have done some modifications in Web.config and globals.asax file giving some extra time limit, but the session is not working for the given time. 我对Web.config和globals.asax文件做了一些修改,给出了一些额外的时间限制,但是会话在给定的时间内无法正常工作。 Sometimes getting expired very soon. 有时很快就会过期。

Web.config: Web.config文件:

 <sessionState mode="InProc" customProvider="DefaultSessionProvider" timeout="60000"/>

 <authentication mode="Forms">
      <forms loginUrl="~/Home/Login" timeout="28880"/>
 </authentication>

Global.asax/session_start(): Global.asax中/在session_start():

 Session.Timeout = 1200;

I added namespaces for the session wherever required, but still the session problem persists, session is stateless after all coding is done. 我在需要的地方为会话添加了名称空间,但是会话问题仍然存在,所有编码完成后,会话是无状态的。

Please can anyone suggest a proper solution, or if my flow is ambiguous, please let me know how to do it in a standard manner. 请任何人提出适当的解决方案,或者如果我的流程不明确,请让我知道如何以标准方式进行。

Thanks. 谢谢。 Help will be appreciated. 帮助将不胜感激。

You are providing timeout in 2 different places I mean u need to provide timeout either in web.config or in global.asax file so better remove timeout declaration from global.asax.. 您在2个不同的位置提供超时,我的意思是您需要在web.config或global.asax文件中提供超时,以便更好地从global.asax中删除超时声明。

as documeneted here http://www.aspdotnet-suresh.com/2010/10/session-timeout-problem-in-aspnet.html :- 如此处http://www.aspdotnet-suresh.com/2010/10/session-timeout-problem-in-aspnet.html中所提:

By default our websites session timeout is 20 mins after that session will gets expire suppose if we want to set our custom timeout in our applications we can set it in different ways (web.config, global.asax and in IIS) 默认情况下,我们的网站会话超时是该会话过期后的20分钟,假设如果我们想在应用程序中设置自定义超时,则可以通过不同的方式(web.config,global.asax和IIS)进行设置

Check below methods to set session timeout in web.config, global.asax and in iis 检查以下方法以在web.config,global.asax和iis中设置会话超时

In Web.config file we can set session timeout like as shown below 在Web.config文件中,我们可以设置会话超时,如下所示

<configuration>
> 
> <system.web>
> 
>  <sessionState mode="InProc" timeout="60">
> 
>  </sessionState>
> 
>  </system.web>
> 
> </configuration> 

In Global.asax file we can set session timeout in Session_Start event like this 在Global.asax文件中,我们可以像这样在Session_Start事件中设置会话超时

void Session_Start(object sender, EventArgs e)
> 
> {
> 
> // Code that runs when a new session is started
> 
> Session.Timeout = 15;
> 
> }

If you set session time out in both web.config and in your iis the iis session out value overrides web.config session time out 如果在web.config和iis中都设置了会话超时,则iis会话超时值将覆盖web.config会话超时

If above solution doesn't work than remove 如果上述解决方案不起作用,则删除

<authentication mode="Forms">
  <forms timeout="50"/>

from web.config file 从web.config文件

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

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