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


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");

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM