自动重定向会话超时后登录 [英] Auto redirect to login after session timeout
问题描述
我尝试后会话超时自动重定向到我的登录页面。
我试图添加此code在我Main.Master页(所有其他网页连接到此母版页):
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
//重定向之前3秒会话超时到登录页面
Response.AppendHeader(重定向,Convert.ToString((查看Session.Timeout * 60) - 3)+; URL =〜/的Login.aspx);
}
我配置了会话超时1分钟在我的web配置:
<的sessionState模式=是InProc无Cookie =假超时=1/>
但没有任何反应。
谁能帮我找到这个code中的问题,还是有其他的想法如何使它工作?
修改:从web.config中验证节点
<身份验证模式=表格>
<CAuthenticated形式的名称= loginUrl =的Login.aspx保护=全部
超时=20/>
< /认证>
AppendHeader
被记录在案,如果引起异常头HTTP标头之后追加已发送您需要确保AppendHeader被称为HTTP头已经被发送之前。根据您的主页上,在加载
事件可能为时已晚。你可以尝试初始化
事件来代替。
I am trying to redirect automatically to my login page after session times out. I tried to add this code in my Main.Master page (all the other pages are connected to this master page):
protected void Page_Load(object sender, EventArgs e)
{
//Redirects to Login Page 3 seconds before session timeout
Response.AppendHeader("Redirect", Convert.ToString((Session.Timeout * 60) - 3) + "; URL=~/Login.aspx");
}
I configured the session timeout to 1 minute in my web config:
<sessionState mode="InProc" cookieless="false" timeout="1"/>
but nothing happens
Can anyone help me find the problem with this code, or has other ideas how to make it work?
Edit: Authentication node from web.config
<authentication mode="Forms">
<forms name=".CAuthenticated" loginUrl="Login.aspx" protection="All"
timeout="20"/>
</authentication>
AppendHeader
is documented as causing an exception if "header is appended after the HTTP headers have been sent" You need to make sure AppendHeader is called before the HTTP headers have been sent. Depending on your master page, the Load
event might be too late. You could try the Init
event instead.
这篇关于自动重定向会话超时后登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!