MVC小系列(二十二)【MVC的Session超时,导致的跳转问题】

由于mvc内部跳转机制的问题,它只在当前的action所渲染的view上进行跳转,如果希望在当前页面跳,需要将mvc方法改为js方法:

 filterContext.Result = new RedirectToRouteResult("Default", new RouteValueDictionary { 
                      { "Action",_failActionName },
                      { "Controller", _failControllerName}, 
                      { "returnUrl", returnUrl} });

修改成Js方法跳转:

 

 string url = new UrlHelper(filterContext.RequestContext).Action(
                _failActionName,
                _failControllerName,
                new
                {
                    returnUrl = returnUrl
                });
  //防止出现登陆超时,在局部跳转URL的问题
   filterContext.HttpContext.Response.Write("<script>location.href='" + url + "'</script>");
   filterContext.HttpContext.Response.End();

 

posted @ 2016-06-29 15:02  那就让我这样吧  阅读(265)  评论(0编辑  收藏  举报