April 2017
Intermediate to advanced
564 pages
24h 7m
English
When using Identity middleware, adding claims is not as simple as with cookie middleware. We need to create a custom claims factory class that derives from the UserClaimsPrincipalFactory class and overrides the CreateAsync method that injects the user object. When the user is signed in, these claims will automatically be added in the cookie.
To create the claims factory class, add the following code:
public class AppClaimsPrincipalFactory : UserClaimsPrincipalFactory<ApplicationUser, IdentityRole> { public AppClaimsPrincipalFactory( UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager, IOptions<IdentityOptions> optionsAccessor) : base( userManager, roleManager, optionsAccessor) ...Read now
Unlock full access