加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

在ASP.NET 5中获取AuthenticationProperties

发布时间:2020-12-16 00:12:48 所属栏目:asp.Net 来源:网络整理
导读:在ASP.NET 5 MVC 6 RC1中,如何从控制器或过滤器中检索AuthenticationProperties? HttpContext.Authentication似乎没有这个功能. 我考虑过注册CookieAuthenticationEvents.OnValidatePrincipal处理程序,然后使用CookieValidatePrincipalContext参数上的Prope
在ASP.NET 5 MVC 6 RC1中,如何从控制器或过滤器中检索AuthenticationProperties? HttpContext.Authentication似乎没有这个功能.

我考虑过注册CookieAuthenticationEvents.OnValidatePrincipal处理程序,然后使用CookieValidatePrincipalContext参数上的Properties属性.然后我可以将这些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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读