【问题标题】:How to maintain session timeout for long period in asp.net mvc4?如何在asp.net mvc4中长时间保持会话超时?
【发布时间】:2014-06-10 06:57:39
【问题描述】:

我在 Web.config 和 globals.asax 文件中做了一些修改,给出了一些额外的时间限制,但会话在给定时间内无法正常工作。有时很快就会过期。

Web.config:

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

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

Global.asax/session_start():

 Session.Timeout = 1200;

我在需要的地方为会话添加了命名空间,但会话问题仍然存在,所有编码完成后会话是无状态的。

请任何人提出适当的解决方案,或者如果我的流程模棱两可,请让我知道如何以标准方式进行。

谢谢。我们将不胜感激。

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-4 session-timeout


    【解决方案1】:

    您在 2 个不同的地方提供超时我的意思是您需要在 web.config 或 global.asax 文件中提供超时,因此最好从 global.asax 中删除超时声明..

    如文档所述http://www.aspdotnet-suresh.com/2010/10/session-timeout-problem-in-aspnet.html :-

    默认情况下,我们的网站会话超时是该会话后 20 分钟 将过期假设如果我们想在我们的 应用程序,我们可以用不同的方式设置它(web.config,global.asax 并在 IIS 中)

    检查以下方法以在 web.config、global.asax 中设置会话超时 并在 iis 中

    在 Web.config 文件中,我们可以设置会话超时,如下所示

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

    在 Global.asax 文件中,我们可以在 Session_Start 事件中设置会话超时 像这样

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

    如果您在 web.config 和 iis 中都设置了会话超时,则 iis 会话超时值覆盖 web.config 会话超时

    【讨论】:

      【解决方案2】:

      如果上述解决方案不起作用,则删除

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

      来自 web.config 文件

      【讨论】:

      • 您能解释一下为什么这会有所帮助吗?此外,您应该链接到您所指的答案,因为它并不总是高于您的答案。 (点击“分享”获取链接。)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      • 2012-01-02
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      • 2011-01-17
      • 2012-11-26
      相关资源
      最近更新 更多