然后用chrome 开发工具查看,其实那个链接是被重定向了,HTTP 状态码 301 (Permanently Moved), 来源 from disk cache , 看来是被浏览器缓存了,再查看之前别人写的登录过滤器,原来是RedirectToRoutResult多加了一个参数,把true去掉应该就可以了,去掉之后测试,那个奇怪的问题就解决了。
结论:越是奇怪的问题越低级
代码如下:
public void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext) { if(CheckLogin) //可以定制 { Staff staff = (Staff)filterContext.HttpContext.Session[SysConstant.STAFF]; if (staff == null) { if (filterContext.HttpContext.Request.IsAjaxRequest()) //判断是否ajax请求 { filterContext.Result = new System.Web.Mvc.JsonResult() { Data = new {Code = 301 ,Msg="会话失效,请重新登录"}, ContentEncoding = System.Text.Encoding.UTF8, JsonRequestBehavior = JsonRequestBehavior.AllowGet, ContentType = "json" }; return; } else { filterContext.Result = new RedirectToRouteResult( "Default", new System.Web.Routing.RouteValueDictionary(new Dictionary<string, object>() { { "controller", "Home" }, { "action", "Login" } },true)); //重定向 return; } } } }