首页 新闻 赞助 找找看

关于MVC BaseController重定向的问题

0
悬赏园豆:30 [已解决问题] 解决于 2016-06-15 13:44

 我在 BaseController 里面做了登录验证,如果没有登录则跳转到登录页。

 所有的操作是要在登录状态下才能执行。

 现在发现会把 Controller 里的 Action 走完了才会重定向。虽然最后都会重定向但方法还是执行。

 有什么办法只重定向, Controller 里的 Action 不执行

下面是重定向的代码

  protected override void OnAuthentication(AuthenticationContext filterContext)
        {
            if (CurrentUser == null)
            {
                filterContext.HttpContext.Response.Redirect("/Login/Index");
                return;
            }

            base.OnAuthentication(filterContext);
        }

 

 

 

xmj112288的主页 xmj112288 | 初学一级 | 园豆:126
提问于:2016-06-15 13:36
< >
分享
最佳答案
0

改变重定向的方式就行

filterContext.Result = RedirectToRoute(new { Controller = "LoginPc", Action = "Index" });

xmj112288 | 初学一级 |园豆:126 | 2016-06-15 13:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册