asp.net-mvc-5 – 如何添加声明在ASP.NET身份

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-5 – 如何添加声明在ASP.NET身份前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图找到一个文档或示例,如何使用ASP.NET身份在MVC 5中添加自定义声明的用户身份。该示例应该显示在OWIN安全管道中插入声明的位置,以及如何使用表单身份验证将它们持久化在cookie中。

解决方法

也许 following article可以帮助:
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name,"Brock"));
claims.Add(new Claim(ClaimTypes.Email,"brockallen@gmail.com"));
var id = new ClaimsIdentity(claims,DefaultAuthenticationTypes.ApplicationCookie);

var ctx = Request.GetOwinContext();
var authenticationManager = ctx.Authentication;
authenticationManager.SignIn(id);
原文链接:https://www.f2er.com/aspnet/254070.html

猜你在找的asp.Net相关文章