我试图找到一个文档或示例,如何使用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,"[email protected]")); var id = new ClaimsIdentity(claims,DefaultAuthenticationTypes.ApplicationCookie); var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignIn(id);