我正在尝试在会话超时后自动重定向到登录页面。
我尝试在我的Main.Master页面中添加以下代码(所有其他页面都连接到此主页面):
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");
}
我在web.config中将会话超时设置为1分钟:
<sessionState mode="InProc" cookieless="false" timeout="1"/>
但是没有任何反应。
有人能帮我找到代码的问题吗?或者有其他想法可以使它正常工作吗?
编辑:来自web.config的身份验证节点。
<authentication mode="Forms">
<forms name=".CAuthenticated" loginUrl="Login.aspx" protection="All"
timeout="20"/>
</authentication>
Response.AppendHeader("Redirect", 60)
这是令服务器在响应浏览器请求时,将浏览器重定向到另一个页面的代码。如果您需要更多关于此的参考资料,请问一下其他开发者是否有相关经验或者查阅相关文档。 - Robin Maben