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