如何在asp.net中增加会话超时?

时间:2021-03-08 03:26:59

I tried following codes to increase session timeout, but no use,

我尝试遵循代码来增加会话超时,但没有用,

code is:

代码是:

<sessionState mode="InProc" cookieless="true" timeout="60">
</sessionState>

Also code at

同时代码

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

6 个解决方案

#1


23  

You can increase the session time-out in asp.net in any one of the following ways

可以通过以下任何一种方法增加asp.net中的会话超时

Using IIS Version 7 :

使用IIS版本7:

  1. Open up IIS
  2. 打开IIS
  3. Select your website from the list of sites
  4. 从网站列表中选择你的网站
  5. Click on Session state on the right
  6. 单击右边的会话状态
  7. Now enter your session timeout under the cookie settings
  8. 现在在cookie设置下输入会话超时。

OR

Web.config : Open up your web.config file and under the system.web section add the following :

网络。配置:打开你的网络。配置文件和系统下。web部分添加以下内容:

<sessionState timeout = "20" mode = "InProc" />

Replace 20 with whatever number you wish.

用你想要的数字替换20。

OR

Global.asax file : Under the Session_Start method, set the timeout property of the session to the required value like this

全球。asax文件:在Session_Start方法下,将会话的超时属性设置为如下所示的所需值

Session.Timeout = "20";

Note : If you are setting a session timeout in both IIS as well as web.config, then the one in IIS will override the one in web.config

注意:如果您正在设置IIS和web中的会话超时。配置,然后IIS中的一个将覆盖web.config中的一个

Hope this helps!

希望这可以帮助!

#2


0  

I wanted to add my final solution. After reading that setting it in the config was "incorrect".

我想把最后的解相加。在读取该配置之后,将其设置为“不正确”。

            if (model.RememberMe)
            {
                var ASPCookie = Request.Cookies["ASP.NET_SessionId"];
                ASPCookie.Expires = DateTime.Now.AddDays(15);
                Response.SetCookie(ASPCookie);
            }

#3


0  

If you are using forms authentication then the default value of session timeout is 30min.Try this code to increase session timeout.

如果您正在使用表单身份验证,那么会话超时的默认值是30min。尝试此代码以增加会话超时。

<system.web>
  <authentication mode="Forms">
      <forms timeout="70"/>
  </authentication>
  <sessionstate timeout="80"/>
</system.web>

I think the code help you.

我认为代码对你有帮助。

#4


0  

simply,go WebConfig,then set it,

简单,去WebConfig,然后把它,

        <system.web>
    <sessionState timeout="60"></sessionState>
  <compilation debug="true" targetFramework="4.0" />
</system.web>

#5


0  

 <sessionState cookieless="false" timeout="30" mode="InProc"/>
  <authentication mode="Forms">
      <forms name="AppRootForms" loginUrl="LoginPage.aspx" protection="All" timeout="30" path="/" slidingExpiration="true"/>
    </authentication>
<system.webServer>
     <!--<max limit for storing session />-->
    <asp>
         <session allowSessionState="true" max="100000" timeout="00:30:00" />
    </asp>
</system.webServer>

#6


-1  

<system.web>
  <authentication mode="Forms">
      <forms timeout="70"/>
         </authentication>
           <sessionState timeout="80"/>
               </system.web>

it works for me

它适合我

copy it to your webconfig file

复制到您的webconfig文件。

#1


23  

You can increase the session time-out in asp.net in any one of the following ways

可以通过以下任何一种方法增加asp.net中的会话超时

Using IIS Version 7 :

使用IIS版本7:

  1. Open up IIS
  2. 打开IIS
  3. Select your website from the list of sites
  4. 从网站列表中选择你的网站
  5. Click on Session state on the right
  6. 单击右边的会话状态
  7. Now enter your session timeout under the cookie settings
  8. 现在在cookie设置下输入会话超时。

OR

Web.config : Open up your web.config file and under the system.web section add the following :

网络。配置:打开你的网络。配置文件和系统下。web部分添加以下内容:

<sessionState timeout = "20" mode = "InProc" />

Replace 20 with whatever number you wish.

用你想要的数字替换20。

OR

Global.asax file : Under the Session_Start method, set the timeout property of the session to the required value like this

全球。asax文件:在Session_Start方法下,将会话的超时属性设置为如下所示的所需值

Session.Timeout = "20";

Note : If you are setting a session timeout in both IIS as well as web.config, then the one in IIS will override the one in web.config

注意:如果您正在设置IIS和web中的会话超时。配置,然后IIS中的一个将覆盖web.config中的一个

Hope this helps!

希望这可以帮助!

#2


0  

I wanted to add my final solution. After reading that setting it in the config was "incorrect".

我想把最后的解相加。在读取该配置之后,将其设置为“不正确”。

            if (model.RememberMe)
            {
                var ASPCookie = Request.Cookies["ASP.NET_SessionId"];
                ASPCookie.Expires = DateTime.Now.AddDays(15);
                Response.SetCookie(ASPCookie);
            }

#3


0  

If you are using forms authentication then the default value of session timeout is 30min.Try this code to increase session timeout.

如果您正在使用表单身份验证,那么会话超时的默认值是30min。尝试此代码以增加会话超时。

<system.web>
  <authentication mode="Forms">
      <forms timeout="70"/>
  </authentication>
  <sessionstate timeout="80"/>
</system.web>

I think the code help you.

我认为代码对你有帮助。

#4


0  

simply,go WebConfig,then set it,

简单,去WebConfig,然后把它,

        <system.web>
    <sessionState timeout="60"></sessionState>
  <compilation debug="true" targetFramework="4.0" />
</system.web>

#5


0  

 <sessionState cookieless="false" timeout="30" mode="InProc"/>
  <authentication mode="Forms">
      <forms name="AppRootForms" loginUrl="LoginPage.aspx" protection="All" timeout="30" path="/" slidingExpiration="true"/>
    </authentication>
<system.webServer>
     <!--<max limit for storing session />-->
    <asp>
         <session allowSessionState="true" max="100000" timeout="00:30:00" />
    </asp>
</system.webServer>

#6


-1  

<system.web>
  <authentication mode="Forms">
      <forms timeout="70"/>
         </authentication>
           <sessionState timeout="80"/>
               </system.web>

it works for me

它适合我

copy it to your webconfig file

复制到您的webconfig文件。