如何保持会话活跃 [英] how to keep session alive

查看:62
本文介绍了如何保持会话活跃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在asp.net和C#上设计一个项目,但会话存在问题,
在我的项目中,我已将会话超时设置为1440分钟(24小时),但是会话很快就会过期.我想让会话不受限制.
在IIS上发布项目后,会话也很快到期.
我是这个主题的新手,任何人都可以对此提供帮助.

I''m designing a project on asp.net & C#, i''ve problem with the sessions,
in my project i''ve given the session time-out to 1440 min(24 hours), but the session expires very soon.i want to put the session unlimited.
after publishing the project on IIS also the session expires soon.
i''m new to this topic anyone can please help on this.

推荐答案

这可能不是最好的方法,但是它可以防止会话超时,因为只要用户正在访问页面,会话就会在用户离开页面后很快超时.

在ASP.NET页上放置一个计时器,设置间隔时间,即1分钟.
This might not be the best method, but it can prevent session from being time out as long as the user is accessing the page and the session will timeout very soon after the user leave the page.

Place a timer on the ASP.NET page, set the interval time, i.e. 1 minute.
<asp:timer id="Timer1" runat="server" interval="60000" ontick="Timer1_Tick" xmlns:asp="#unknown"></asp:timer>


并添加UpdatePanel以异步处理timer1滴答事件.


and add UpdatePanel to handle the timer1 tick event asynchronously.

<asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
    <triggers>
        <asp:asyncpostbacktrigger controlid="Timer1" eventname="Tick">
        </asp:asyncpostbacktrigger>
    </triggers>
</asp:updatepanel>


在计时器的tick事件中,在后面的代码中,您什么也不做.


at the code behind, inside the timer''s tick event, you do nothing.

protected void Timer1_Tick(object sender, EventArgs e)
{

}


一旦timer1引发滴答事件,会话超时将重置并保持活动状态.
然后,您可以将会话超时设置为更短的时间.


once the timer1 raises the tick event, the session time out is reset and kept alive.
then, you can set the session time out to a shorter time.


在web.config中使用超时,默认情况下也可以使用timepan--20分钟,而且无法设置timeout属性对于进程内和状态服务器模式,此值大于525,601分钟(1年).
< sessionstate>
mode ="[关闭| InProc | StateServer | SQLServer |自定义]"
timeout =分钟数"
............

希望有帮助!
Use timeout in web.config, can also use timespan--20 minutes is default, also The timeout attribute cannot be set to a value that is greater than 525,601 minutes (1 year) for the in-process and state-server modes.
<sessionstate>
mode="[Off|InProc|StateServer|SQLServer|Custom]"
timeout="number of minutes"
............

Hope that helps!


这篇关于如何保持会话活跃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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