如何在一段时间后过期? [英] How to expire the session after some time?

查看:122
本文介绍了如何在一段时间后过期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一段时间后使会话过期?

How to expire the session after some time?

推荐答案

几种方式:

1.您可以在Web中更改会话超时值的.config。例如,如果需要会话超时为20分钟,web.config中的标记代码应如下所示:

Several ways:
1. You can change session timeout value in web.config. Example, if desired session timeout is 20 minutes, markup code in web.config should look like this:
<sessionstate timeout="60" mode="InProc""></sessionstate>



SessionState元素位于


SessionState element is located under

<system.web></system.web>

命名空间。

您可以通过编程方式更改ASP.NET会话超时

2.您可以从代码更改会话超时。例如,要将会话时间减少到10分钟,请使用:

namespace.
you can change ASP.NET session timeout programmatically
2. you can change session timeout from code. example, to decrease session time to 10 minutes, use:

Session.Timeout = 10;



3.更改会话超时的另一种方法是使用IIS管理器。打开控制面板 - >管理工具 - > IIS管理器 - >选择所需的网站 - >在ASP.NET部分右侧打开会话状态 - >最后,在表单底部名为超时(以分钟为单位)的文本框中,更改默认值。如果您使用IIS 7,这是方法,但它也适用于早期版本。在IIS 6上,右键单击所选网站 - >选择属性 - >在弹出的对话框中选择ASP.NET选项卡 - >并更改超时值。

4.如果您使用表单身份验证,您可能还需要使用web.config中的标记代码来增加表单超时,如下所示:




3. One more way to change session timeout is using IIS Manager. Open Control Panel -> Administrative Tools -> IIS Manager -> Select desired web site -> in ASP.NET section on right side open Session State -> and finally, in text box named "Time-out (in minutes)" on the bottom of the form, change default value. This is the method if you use IIS 7, but it is similar for earlier versions too. On IIS 6, right click on selected website -> choose Properties -> in pop up dialog select ASP.NET tab -> and change timeout value.
4. if you use Forms Authentication, you'll probably need to increase forms timeout too, using markup code in web.config like this:

<system.web>
      <authentication mode="Forms">
        <forms timeout="60" />
    </authentication>



希望有帮助


Hope it helps


你的时间分钟



Session.Timeout = 20;
your time in minutes

Session.Timeout = 20;


使用代码或web.config设置Session.Timeout ...

此示例将其设置为30分钟!

Set Session.Timeout using code or your web.config...
This sample set it to 30 minutes!
<configuration>
  <system.web>
    <sessionstate mode="InProc" timeout="30" />
  </system.web>
</configuration>


这篇关于如何在一段时间后过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆