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");
测试后可行,问题解决了,但是不知道是什么原因,最开始那个没有成功。个人猜测是环境的原因,所以以后还是用后面这种,都可以执行跳转。
最新文章
- Mina、Netty、Twisted一起学(八):HTTP服务器
- [每日电路图] 9、介绍一种低价简单的4.2V锂电池充电及稳压(LDO)电路——RT9193,SD8017
- CSS3样式运用,悬浮立体方块
- mongodb windows下的安装
- bzoj3503
- SQL 2005远程连接是出错(provider: SQL 网络接口, error: 28 - 服务器不支持请求的协议
- ubuntu matplotlib 安装
- C#游戏框架uFrame
- AFNetworking 用法详解
- 手機Web頁面信息
- Linux创建普通用户
- Windows安装Git
- Wireshark:couldn&#39;t run dumpcap in child process(附带Linux下探索过程)
- SpringBoot 配置阿里巴巴Druid连接池
- Consul集群搭建
- 解决U盘拷贝时提示文件过大问题(不能拷贝超过4个g的文件)
- JavaScript判断变量是否为数组的方法(Array)
- DataWindow.Net组件示例(全部开源)
- 字符编解码的故事(ASCII,GBK,Unicode,Utf-8区别)
- jmGraph:一个基于html5的简单画图组件