Bum*_*Bee 5 asp.net session response.redirect
我有 Default.aspx 页,它继承自 BasePage.cs,它继承自 System.Web.UI.Page。BasePage 是我检查会话是否超时的地方。当会话超时并且用户单击某些内容时,我需要将用户重定向回“Main.aspx”页面。
这是我的 Basepage 中的代码
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
if (Context.Session != null)
{
if (Session.IsNewSession)
{
string cookie = Request.Headers["Cookie"];
if ((null != cookie) && (cookie.IndexOf("ASP.NET_SessionId") >= 0))
{
HttpContext.Current.Response.Redirect("Main.aspx", true);
return;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
HttpContext.Current.Response.Redirect("Main.aspx", true);
我希望重定向停止执行 BasePage 并立即跳出。问题是,它没有。
当我在调试模式下运行时,它继续单步执行,就好像它不只是重定向并离开一样。如何安全地重定向?
看到您的基类继承自System.Web.UI.Page,您不需要使用HttpContext。尝试不使用它,看看是否有帮助。
编辑:添加了围绕response.redirect的页面检查
if (!Request.Url.AbsolutePath.ToLower().Contains("main.aspx"))
{
Response.Redirect("<URL>", false);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11584 次 |
| 最近记录: |