简体   繁体   English

如何在 asp.net 5 中创建 ClaimIdentity

[英]How to create a ClaimIdentity in asp.net 5

In old asp.net identity 2.0, there is a CreateIdentityAsync() method in type Microsoft.AspNet.Identity.UserManager.在旧的 asp.net 身份 2.0 中,Microsoft.AspNet.Identity.UserManager 类型中有一个 CreateIdentityAsync() 方法。 But now asp.net 5 has removed this method, how can I create a ClaimsIdentity representing the user now?但是现在asp.net 5已经删除了这个方法,我现在如何创建一个代表用户的ClaimsIdentity? Thanks in advance.提前致谢。

public virtual Task<ClaimsIdentity> CreateIdentityAsync(TUser user, string authenticationType);

Is this what you are looking for?这是你想要的?

http://aspnet-docs-example.readthedocs.org/en/latest/autoapi/Microsoft/AspNet/Identity/IUserClaimsPrincipalFactory-TUser/ http://aspnet-docs-example.readthedocs.org/en/latest/autoapi/Microsoft/AspNet/Identity/IUserClaimsPrincipalFactory-TUser/

IUserClaimsPrincipalFactory Interface IUserClaimsPrincipalFactory 接口

Provides an abstraction for a factory to create a System.Security.Claims.ClaimsPrincipal from a user.为工厂提供抽象以从用户创建 System.Security.Claims.ClaimsPrincipal。

This has been changed to UserManager.CreateAsync and returns an IdentityResult indicating whether or not the new user was successfully created.这已更改为 UserManager.CreateAsync 并返回一个 IdentityResult,指示新用户是否已成功创建。

If you want to add Claims, you can do this via UserManager.AddClaimAsync.如果您想添加声明,您可以通过 UserManager.AddClaimAsync 执行此操作。

在这里,您可以找到如何使用带有示例可downloadable project ClaimIdentity示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM