Skip to content

UserManager.GetRolesAsync fails to work for me #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
skippyV opened this issue May 21, 2025 · 0 comments
Open

UserManager.GetRolesAsync fails to work for me #141

skippyV opened this issue May 21, 2025 · 0 comments

Comments

@skippyV
Copy link

skippyV commented May 21, 2025

Hello, not sure if I'm using the GetRolesAsync() incorrectly.
Code repo
Apologies for the formatting of this post. Can't seem to get it all in the code block.
`
bool CheckIfUserIsSuperAdmin(ApplicationUser user)
{
if (user is not null)
{
List rolesIDsList = user.Roles;

    foreach (var roleId in rolesIDsList)
    {
        Task<ApplicationRole?> roleTask = _RoleManager.FindByIdAsync(roleId);
        roleTask.Wait();
        if(roleTask.Result is not null)
        {
            ApplicationRole role = roleTask.Result;
            if (role.Name!.Equals(Constants.SUPERADMIN))
            {
                //return true; // this works - BUT commenting it out to allow code below to run.
                break;
            }
        }
    }
    
    // BELOW CODE DOES NOT WORK
    Task<IList<string>> rolesListResult = _UserManager.GetRolesAsync(user); // HANGS here
    rolesListResult.Wait();
    if (rolesListResult.Result is not null)
    {
        IList<string> roles = rolesListResult.Result;
        if(roles.Contains(Constants.SUPERADMIN))
        {
            return true;
        }
    }
}

return false;

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant