我在 BaseController 里面做了登录验证,如果没有登录则跳转到登录页。
所有的操作是要在登录状态下才能执行。
现在发现会把 Controller 里的 Action 走完了才会重定向。虽然最后都会重定向但方法还是执行。
有什么办法只重定向, Controller 里的 Action 不执行
下面是重定向的代码
protected override void OnAuthentication(AuthenticationContext filterContext) { if (CurrentUser == null) { filterContext.HttpContext.Response.Redirect("/Login/Index"); return; } base.OnAuthentication(filterContext); }
改变重定向的方式就行
filterContext.Result = RedirectToRoute(new { Controller = "LoginPc", Action = "Index" });