ASP.NET Core Identity Configuration Issues with Custom Claims
I'm having trouble adding custom claims to user profiles in my ASP.NET Core 6.0 application that uses Identity. I've set up the Identity framework and I'm able to register and log in users without any issues. However, I want to add a custom claim called 'SubscriptionType' upon user registration. I thought I could achieve this by overriding the `OnPostAsync` method in my `RegisterModel`, but the claim isn't being added as expected. Here's what I tried in my `RegisterModel`: ```csharp public class RegisterModel : PageModel { private readonly UserManager<ApplicationUser> _userManager; public RegisterModel(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IActionResult> OnPostAsync(RegisterInputModel input) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = input.Email, Email = input.Email }; var result = await _userManager.CreateAsync(user, input.Password); if (result.Succeeded) { // Adding custom claim here await _userManager.AddClaimAsync(user, new Claim("SubscriptionType", input.SubscriptionType)); await _signInManager.SignInAsync(user, isPersistent: false); return LocalRedirect(returnUrl); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return Page(); } } ``` In the above code, after the user is created, I attempt to add the `SubscriptionType` claim. However, when I check the claims using `User.Claims` after logging in, I don't see the 'SubscriptionType' claim at all. I've also verified that `input.SubscriptionType` is being set correctly from the registration form. I'm not encountering any exceptions or errors, so I suspect it might be an issue with how claims are being handled in the Identity system. What could I be missing here? Is there something specific I need to configure in the Identity options or claim types that I'm overlooking? Any insights would be greatly appreciated! For context: I'm using Csharp on macOS. What am I doing wrong?