Asp.net会话过期重定向到登录页面 [英] Asp.net session expiry redirect to login page

查看:654
本文介绍了Asp.net会话过期重定向到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是重定向到登录页面时,会话过期的最佳方法。我使用的是

What is the best way to redirect to the login page when the session expires. I'm using

sessionState mode="InProc"

我可以设置在web.config文件?

Can I set this in the web.config file?

推荐答案

要记住会话过期的诀窍是,这发生在运行幕后的工作进程并没有直接的方法,而无需通知用户返回到服务器,检查事物的状态。

The trick to remember about the session expiration is that this happens in the the worker process running behind the scenes and there is no direct way to notify the user without going back to the server to check the state of things.

我做的是我在页面注册一个Javascript模块,将用户重新指定超时后重定向到登录页面:

What I do is I have the page register a Javascript block that will redirect the user to the login page again after the designated timeout:

Page.ClientScript.RegisterStartupScript(Me.GetType, "TimeoutScript", 
"setTimeout(""top.location.href = '~/Login.aspx'""," &
 ConfigurationManager.AppSettings("SessionTimeoutMilliseconds") & ");", True)

您会发现,我已经保存在我的w​​eb.config文件中的实际毫秒,这样的需要,我可以调整超时长度。

You'll notice that I have the actual milliseconds stored in my web.config file so that I can adjust the timeout length as needed.

利用这一点,再加上在Global.asax文件中的典型Session_End中的事件作出处理会话超时在我的web应用程序一个pretty的清洁方式。

Using this, combined with the typical Session_End event in the Global.asax file makes a pretty clean way of handling session timeouts in my web apps.

这篇关于Asp.net会话过期重定向到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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