vendredi 27 décembre 2019

User.IsInRole("Admin") returning always false in _Layout.cshtml

In layout.cshtml I am checking whether the current user is an admin or not. If so, then a different menu is shown. However, it is always returning false, even when logging in with an admin. I am using the code below:

@if (User.Identity.IsAuthenticated == false)
{
    <li><a href="\Users\Login">Log in</a></li>
    <li><a href="\Users\Register">Register</a></li>
}

else
{
    <li><a href="\Users\Logout">Log out</a></li>
    if (User.IsInRole("Admin"))
    {
        <li><a href="\Users\List">Users List</a></li>
    }
}



Aucun commentaire:

Enregistrer un commentaire