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

David Thielen 3,216 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

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.