问题
In old asp.net identity 2.0, there is a CreateIdentityAsync() method in type Microsoft.AspNet.Identity.UserManager. But now asp.net 5 has removed this method, how can I create a ClaimsIdentity representing the user now? Thanks in advance.
public virtual Task<ClaimsIdentity> CreateIdentityAsync(TUser user, string authenticationType);
回答1:
Is this what you are looking for?
http://aspnet-docs-example.readthedocs.org/en/latest/autoapi/Microsoft/AspNet/Identity/IUserClaimsPrincipalFactory-TUser/
IUserClaimsPrincipalFactory Interface
Provides an abstraction for a factory to create a System.Security.Claims.ClaimsPrincipal from a user.
回答2:
This has been changed to UserManager.CreateAsync and returns an IdentityResult indicating whether or not the new user was successfully created.
If you want to add Claims, you can do this via UserManager.AddClaimAsync.
回答3:
Here you can find how to work with ClaimIdentity example with a sample downloadable project
来源:https://stackoverflow.com/questions/33737757/how-to-create-a-claimidentity-in-asp-net-5