1. 程式人生 > >asp.net mvc cookie超時返回登錄頁面問題

asp.net mvc cookie超時返回登錄頁面問題

vid sig ror ttr resp 執行 bsp filter current

filterContext.HttpContext.Response.Write("<script>top.location.href = ‘/Login/Index‘;</script>");

在使用超時設置時在本機調試時可以返回登錄頁面,在本機部署也可以,但是在服務器部署後沒有跳轉到登錄頁面,報錯,以前的代碼如下:

public class HandlerLoginAttribute : AuthorizeAttribute
{
public bool Ignore = true;
public HandlerLoginAttribute(bool ignore = true)
{
Ignore = ignore;
}
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (Ignore == false)
{
return;
}
if (OperatorProvider.Provider.GetCurrent() == null)
{
WebHelper.WriteCookie("schemedesign_login_error", "overdue");
filterContext.HttpContext.Response.Write("<script>top.location.href = ‘/Login/Index‘;</script>");

return;
}
}
}

困惑了很久,後面看見網上別人的代碼有些不一樣,替換了這段代碼:

filterContext.HttpContext.Response.Write("<script>top.location.href = ‘/Login/Index‘;</script>");

替換為如下:

filterContext.HttpContext.Response.Redirect("/Login/Index");

測試後可行,問題解決了,但是不知道是什麽原因,最開始那個沒有成功。個人猜測是環境的原因,所以以後還是用後面這種,都可以執行跳轉。

asp.net mvc cookie超時返回登錄頁面問題