我试图在会话超时后自动重定向到我的登录页面。
我尝试在我的 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 配置中将会话超时配置为 1 分钟:
<sessionState mode="InProc" cookieless="false" timeout="1"/>
但什么也没发生
谁能帮我找到这段代码的问题,或者有其他想法如何让它工作?
Edit:来自 web.config 的身份验证节点
<authentication mode="Forms">
<forms name=".CAuthenticated" loginUrl="Login.aspx" protection="All"
timeout="20"/>
</authentication>
protected void Page_Init(object sender, EventArgs e)
{
if (Session["Username"] == null)
{
Response.Redirect(ResolveClientUrl("~/login.aspx") + "?returnURL=" + HttpContext.Current.Request.Url.AbsolutePath);
}
else
{
lblUsername.Text = Session["Username"].ToString();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)