在ASP.NET 5 MVC 6 RC1中,如何从 Controller 内部或过滤器中检索AuthenticationProperties
? HttpContext.Authentication
似乎没有此功能。
我考虑过注册一个CookieAuthenticationEvents.OnValidatePrincipal
处理程序,然后在Properties
参数上使用CookieValidatePrincipalContext
属性。然后,我可以将这些AuthenticationProperties
存储在请求缓存中,以便以后可以获取类似IssuedUtc
的内容。
是否有更好的解决方案,不需要我自己存储呢?
我没有使用ASP.NET Identity,而是将cookie中间件作为独立的。
最佳答案
在ASP.NET 5中,检索身份验证属性有点麻烦,因为必须通过实例化AuthenticateContext
来完成:
var context = new AuthenticateContext("[your authentication scheme]");
await HttpContext.Authentication.AuthenticateAsync(context);
if (context.Principal == null || context.Properties == null) {
throw new InvalidOperationException("The request is not authenticated.");
}
var properties = new AuthenticationProperties(context.Properties);
关于asp.net - 在ASP.NET 5中获取AuthenticationProperties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34534892/