如何在Web.config文件表单C#代码中更新会话超时



我想从C#代码更新会话超时

<system.web>
    <sessionState 
      mode="InProc" 
      cookieless="false" 
      timeout="20"/>
</system.web>

我使用 Session.Timeout=50,效果很好,但我想更改web.config文件中的值。

完成操作文件后应像

更新
<system.web>
        <sessionState 
          mode="InProc" 
          cookieless="false" 
          timeout="50"/>
</system.web>

使用session.time.timeout =您的代码中的50。它不会影响您的配置文件。而不是尝试更改web.config global.asax文件的session_start方法和set session.time.time to to to to with with yout with。

更多信息:

https://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.timeout(v = vs.110).aspx

在global.asax

中添加这些行
protected void Session_Start(object src, EventArgs e)
        {
            if (Context.Session != null)
            {
                if (Context.Session.IsNewSession)
                {
                    Context.Session.Timeout = 50;
                }
            }
        }

最新更新