如何创建为Asp.NET MVC 5 ClaimsIdentity对象吗? [英] How do I create a ClaimsIdentity object for Asp.NET MVC 5?
问题描述
我在.NET MVC 5应用程序的工作。我不希望使用实体框架。我想验证到RavenDB数据库。在我看来,我想替换的UserManager
随账户控制器。我想我可以重写所有的UserManager功能与我的数据库工作,但我不明白的 ClaimsIdentity
对象。
在 SignInAsync
方法,也就是通话UserManager.CreateIdentityAsync(...)
。我知道它返回一个 ClaimsIdentity
对象。我不知道是怎么对我自己创建一个ClaimsIdentity对象。
我看到它有4个属性演员
, BootstrapContext
,声明
和标签
。我不知道这些属性用于什么,我不知道如何正确地生成它们。我想他们产生正确很重要,因为它是身份验证cookie是怎么回事。
我看着ClaimsIdentity对象的解释<一个href=\"http://msdn.microsoft.com/en-us/library/system.security.claims.claimsidentity_properties%28v=vs.110%29.aspx\">here,但是这并没有真正帮助我理解。
如果我能看到code为 CreateIdentityAsync()
,这可能会有所帮助。
如果我要对此都错了,请让我知道。否则,如果有人可以点我对如何生成ClaimsIdentity对象,这将是有益的。
ClaimsIdentity身份=新ClaimsIdentity
{
演员= ????,
BootstrapContext = ?????,
声明= ?????,
标签= ?????
}
也许<一个href=\"http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/\">following链接可以帮助:
VAR索赔=新的List&LT;权利要求GT;();
claims.Add(新索赔(ClaimTypes.Name,布洛克));
claims.Add(新索赔(ClaimTypes.Emailbrockallen@gmail.com));
VAR ID =新ClaimsIdentity(索赔,DefaultAuthenticationTypes.ApplicationCookie);VAR CTX = Request.GetOwinContext();
VAR的AuthenticationManager = ctx.Authentication;
authenticationManager.SignIn(ID);
I am working in a .NET MVC 5 application. I do not want to use Entity Framework. I want to authenticate to a RavenDB database. It looks to me that I want to replace the UserManager
that comes with the Account Controller. I think I can rewrite all the UserManager functions to work with my database, except I don't understand the ClaimsIdentity
object.
In the SignInAsync
method, there is a call to UserManager.CreateIdentityAsync(...)
. I know it returns a ClaimsIdentity
object. What I don't know is how to create a ClaimsIdentity object on my own.
I see that it has 4 properties Actor
, BootstrapContext
, Claims
and Label
. I don't know what these properties are used for, and I don't know how to properly generate them. I assume generating them correctly is important since it is how the authentication cookie is made.
I looked at the explanation of the ClaimsIdentity object here, but that didn't really help me understand.
If I could see the code for CreateIdentityAsync()
, that would probably help.
If I'm going about this all wrong, please let me know. Otherwise, if someone could point me toward how to generate the ClaimsIdentity object, that would be helpful.
ClaimsIdentity identity = new ClaimsIdentity
{
Actor = ????,
BootstrapContext = ?????,
Claims = ?????,
Label = ?????
}
Perhaps the following link 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 MVC 5 ClaimsIdentity对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!