ASP.NET Core Identity not adding claims on user creation - advanced patterns
I need some guidance on I'm testing a new approach and I'm dealing with I'm working with an scenario where claims are not being added to the user upon registration in my ASP.NET Core 6 application using Identity..... My registration method looks like this: ```csharp public async Task<IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddClaimAsync(user, new Claim("CustomClaim", "ClaimValue")); // Other post-registration logic return RedirectToAction("Index", "Home"); } AddErrors(result); } return View(model); } ``` Despite the claims being added after a successful user creation, when I try to retrieve them using `User.Claims` in a controller action, the claims do not show up. I've also checked the database, and it appears that the claims are not being stored in the `AspNetUserClaims` table. I have confirmed that the `_userManager` is properly injected, and my `ApplicationUser` class inherits from `IdentityUser`. I've looked through the Identity documentation but need to seem to pinpoint what I'm missing. I've tried moving the `AddClaimAsync` method call to different parts of the registration logic, but the scenario continues. Additionally, I ensured that `AddClaimAsync` is being awaited correctly. I checked the role and policy configurations, but everything seems fine. I also verified that my database migrations are up-to-date. Am I overlooking something here? What could prevent claims from being saved or retrieved after a user is created? Any insight would be greatly appreciated! I'm coming from a different tech stack and learning C#. What's the best practice here? I'm working in a Debian environment. Any examples would be super helpful. This is part of a larger CLI tool I'm building. Any ideas what could be causing this? This is happening in both development and production on Ubuntu 20.04. How would you solve this?