ASP.NET Identity library - delete user does not delete their claims

David Thielen 3,186 Reputation points
2024-01-14T18:15:31.95+00:00

Hi all; I am using the ASP.NET Core Identity library in Blazor server side version 8. The library provides a page for a user to delete themselves from the system. When they are deleted - it does not delete any claims they have. How can I have it delete any associated claims? thanks - dave DeleteUser

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,779 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tiny Wang-MSFT 3,146 Reputation points Microsoft Vendor
    2024-01-15T02:51:37.25+00:00

    Hi @David Thielen , I deduce you are using the default identity code generated by the blazor app template, so that you might also find the DeletePersonalData.razor in Components ->Account -> Pages -> Manage folder. Then I trust you will find that the default delete user action would only delete user account by await UserManager.DeleteAsync(user); User's image

    To delete the rows in the dbo.AspNetUserClaims table, we might manually add code below.

    var claims = await UserManager.GetClaimsAsync(user);
    var res = await UserManager.RemoveClaimsAsync(user, claims);
    

    I had a test in my side which worked well for me. Animation2


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread!

    Best regards,

    Tiny


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.