我有一个名为“SomeController”的控制器。我想检查用户是否已登录,或者是否有权限在该控制器中执行任何操作。为此,我阅读了那篇文章http://blog.wekeroad.com/blog/aspnet-mvc-securing-your-controller-actions/并且我编写了自己的类(测试):
public class BaseFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
}
//here will be checking the user permissions if he's logged in
}
}
[BaseFilter]
public class SomeController : BaseController
{
...
}
但是正如您可以理解的那样,当我想从该控制器运行任何操作时,它会产生一个不定式循环。那么,如何应对呢?