会话超时在ASP.Net中 [英] Session Time out in ASP.Net

查看:84
本文介绍了会话超时在ASP.Net中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在web.cofig文件中设置了会话timeot = 10000.



但是20分钟后显示错误。



请帮我解决这个问题



谢谢

Mohan

Hi,

I Have set session timeot =10000 in my web.cofig file.

But it show error after 20 min.

Please help me to resolve this problem

Thanks
Mohan

推荐答案

默认情况下,会话超时设置为在ASP中过期。 NET在20分钟内完成。

增加超时或到期,您应该在 web.config中更改 SessionState 的超时属性文件

By default, Session timeouts are set to expire in ASP.NET in 20 minutes.
To increase the timeout or expiry you should change the timeout attribute for SessionState in the web.config file
<sessionState  timeout="40" />



请注意,如果您使用的是表单身份验证,则表单超时设置将在设置的超时期限后将用户注销,以便您还必须调整此属性:


Note that if you are using Forms authentication, the Forms timeout setting will log the user out after the set timeout period so you will also have to adjust this attribute:

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



会话超时后将用户重定向到登录页面类似于在某些间隔方法后刷新页面。唯一不同的是计算页面必须重定向的时间。因此,可以使用Session.timeout属性计算时间,该属性将为该会话提供会话超时值。为该值添加一些优雅时间并自动将用户重定向到登录页面。



使用Window.setTimeout方法

在页面中加载事件:


Redirecting user to login page after session timeout is similar to refreshing the page after certain intervals method. Only thing which will differ is that calculating time after which the page has to be redirected. Hence time can be calculated using Session.timeout property which will give us session timeout value for that session. Add some grace timings to that value and redirect the user to the login page automatically.

Using Window.setTimeout method
In the page Load event:

body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 10000 & ");")





使用元标记 - 刷新



Using Meta Tag - Refresh

Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 10) & "; URL=Login.aspx")



这两种方法都会在会话超时+ 10秒后将用户重定向到登录页面。这是如何在会话超时之后将用户重定向到登录页面而无需用户交互。



另请参阅一些CP文章了解更多详情:

ASP.NET中的会话管理选项 [ ^ ]

ASP.NET中的会话管理 [ ^ ]



要在 IIS 上配置会话超时,请参阅解决方案1中Kishore Sharma提供的主题。


Both these methods will redirect the user to login page after session timeout + 10 seconds. This is how you can redirect the user to login page after session timeout without user interaction.

Also refer some CP articles for more details:
Session management options in ASP.NET[^]
Session Management in ASP.NET[^]

To configure Session Time Out on IIS refer the thread provided by Kishore Sharma in Solution 1.


这篇关于会话超时在ASP.Net中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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