use*_*754 9 asp.net asp.net-core-mvc asp.net-core
在ASP.NET 5 MVC 6 RC1中如何AuthenticationProperties从控制器或过滤器中检索?HttpContext.Authentication似乎没有这个功能.
我考虑过注册一个CookieAuthenticationEvents.OnValidatePrincipal处理程序然后Properties在CookieValidatePrincipalContext参数上使用该属性.然后我可以将它们存储AuthenticationProperties在请求缓存中,以便以后我能够得到类似的东西IssuedUtc.
有没有更好的解决方案,我不需要自己存储?
我没有使用ASP.NET身份,而是使用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);
Run Code Online (Sandbox Code Playgroud)
AuthenticationProperties可以通过 访问IAuthenticateResultFeature。它在 AuthN 和 AuthZ 中间件中设置。
HttpContext.Features.Get<IAuthenticateResultFeature>().AuthenticateResult.Properties
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3364 次 |
| 最近记录: |