.NETCORE MVC RedirectToRoute跳转其他页面无效求解到 20
过滤器publicoverridevoidOnActionExecuting(ActionExecutingContextfilterContext){byte[]res...
过滤器
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
byte[] result;
filterContext.HttpContext.Session.TryGetValue(KeyUtil.user_info, out result);
if (result == null)
{
filterContext.Result = RedirectToRoute(new { controller = "Signin", action = "Index", area = "" });
//filterContext.Result = RedirectToRoute(new { controller = "Signin", action = "Index" });
return;
}
base.OnActionExecuting(filterContext);
}
路由
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{controller=Signin}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Signin}/{action=Index}/{id?}");
}); 展开
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
byte[] result;
filterContext.HttpContext.Session.TryGetValue(KeyUtil.user_info, out result);
if (result == null)
{
filterContext.Result = RedirectToRoute(new { controller = "Signin", action = "Index", area = "" });
//filterContext.Result = RedirectToRoute(new { controller = "Signin", action = "Index" });
return;
}
base.OnActionExecuting(filterContext);
}
路由
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{controller=Signin}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Signin}/{action=Index}/{id?}");
}); 展开
2018-12-25 · 百度知道官方认证企业
腾讯电脑管家
腾讯电脑管家是腾讯公司推出的免费安全管理软件,能有效预防和解决计算机上常见的安全风险,并帮助用户解决各种电脑“疑难杂症”、优化系统和网络环境,是中国综合能力最强、最稳定的安全软件。
向TA提问
关注
展开全部
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;
}
}
}
{
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;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询