Search code examples
c#asp.net-coreasp.net-identityasp.net-core-6.0

How to remove claims from current user in ASP.NET Core?


I have a project that is written using C# on the top of ASP.NET Core 6 framework.

After agrees to specific agreement, I want to remove a claim from their current session. How can I remove specific claims from current session?

The UserManager<> provides a method called RemoveClaimsAsync() which I believes remove claims from the store not the claims in the current session.

Is it possible to remove claims from current session without signing out/in?

await _signInManager.SignOutAsync();
await _signInManager.SignInWithClaimsAsync(user, false, upddatedClaims);

Solution

  • After calling the RemoveClaim method, you can call the RefreshSignInAsync(TUser) method to update the Claims accordingly.

    MS Docs reference