Asp.net mvc asp.net MVC中IAAuthenticationFilter接口的实现
我查看了ASP.NET MVC中的控制器类,发现它实现了IAAuthenticationFilter接口。但是,我无法理解如何在控制器中实现其方法OnAuthentication()和OnAuthenticationChallenge(),以及何时调用这些方法Asp.net mvc asp.net MVC中IAAuthenticationFilter接口的实现,asp.net-mvc,Asp.net Mvc,我查看了ASP.NET MVC中的控制器类,发现它实现了IAAuthenticationFilter接口。但是,我无法理解如何在控制器中实现其方法OnAuthentication()和OnAuthenticationChallenge(),以及何时调用这些方法 如果有人能向我解释或与我分享任何解释这一点的链接,这将是非常有帮助的。甚至我在MSDN中也找不到这方面的任何资源。您可以使用它来临时更改HttpContext.User Iprincipal子体对象及其自身值。只需要通过Authentic
如果有人能向我解释或与我分享任何解释这一点的链接,这将是非常有帮助的。甚至我在MSDN中也找不到这方面的任何资源。您可以使用它来临时更改HttpContext.User Iprincipal子体对象及其自身值。只需要通过AuthenticationContext传递新的IPrincipal。我认为,代表另一个用户(暂时)行动是有用的。例如:假期或开发阶段何时更换人员。因此,您可以在VS2013预览MVC5项目中使用 例如,在控制器中(作为IAAuthenticationFilter):
使用
OnAuthentication
设置或修改当前请求的主体
使用OnAuthenticationChallenge验证当前主体并允许执行当前请求。例如:
public class CustomAuthenticatioFilter : ActionFilterAttribute, IAuthenticationFilter
{
public void OnAuthentication(AuthenticationContext filterContext)
{
//Here you are setting current principal
filterContext.Principal = new ClaimsPrincipal();
}
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
//Here you're checking current action and redirecting to ErrorPage
filterContext.Result = new RedirectToRouteResult("ErrorPage",null);
}
}
你找不到任何文档,因为两周前(3月22日)在ASP.NET MVC中添加了提到的
iaAuthenticationFilter
接口:@nemesv-哦,是的,谢谢你的回复,我错了。如果iaAuthenticationFilter
的MSDN文档包含你的前两句话就好了!
public class CustomAuthenticatioFilter : ActionFilterAttribute, IAuthenticationFilter
{
public void OnAuthentication(AuthenticationContext filterContext)
{
//Here you are setting current principal
filterContext.Principal = new ClaimsPrincipal();
}
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
//Here you're checking current action and redirecting to ErrorPage
filterContext.Result = new RedirectToRouteResult("ErrorPage",null);
}
}