在 ASP.NET 5 中获取 AuthenticationProperties
Get AuthenticationProperties in ASP.NET 5
在 ASP.NET 5 MVC 6 RC1 中,如何从控制器或过滤器中检索 AuthenticationProperties
? HttpContext.Authentication
好像没有这个功能。
我考虑过注册一个 CookieAuthenticationEvents.OnValidatePrincipal
处理程序,然后在 CookieValidatePrincipalContext
参数上使用 Properties
属性。然后我可以将那些 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 5 MVC 6 RC1 中,如何从控制器或过滤器中检索 AuthenticationProperties
? HttpContext.Authentication
好像没有这个功能。
我考虑过注册一个 CookieAuthenticationEvents.OnValidatePrincipal
处理程序,然后在 CookieValidatePrincipalContext
参数上使用 Properties
属性。然后我可以将那些 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);