如何在 ASP.NET Identity 中添加声明 [英] How to add claims in ASP.NET Identity

查看:29
本文介绍了如何在 ASP.NET Identity 中添加声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找有关如何使用 ASP.NET Identity 向 MVC 5 中的用户标识添加自定义声明的文档或示例.该示例应显示在 OWIN 安全管道中插入声明的位置以及如何使用表单身份验证将它们保存在 cookie 中.

I am trying to find a document or example of how you would add custom claims to the user identity in MVC 5 using ASP.NET Identity. The example should show where to insert the claims in the OWIN security pipeline and how to persist them in a cookie using forms authentication.

推荐答案

也许 以下文章 可以提供帮助:

Perhaps the following article can help:

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);

这篇关于如何在 ASP.NET Identity 中添加声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆