jeudi 26 décembre 2019

User.Identity.IsAuthenticated always returning false

I am new in web development using c#. Anyway, I was following a tutorial we were doing in class and one of the things we did was a navbar that, once logged in, shows "logout" and once logged out, shows "logged in". We made it work in class however, while doing it alone, I noticed that the navbar kept showing "login", even when I actually logged in.

This is the code in the Layout.cshtml page:

@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>
    }
}

and this is the code in the UsersController class:

public ActionResult Logout()
{
    FormsAuthentication.SignOut();
    return RedirectToAction("Login");
}

Thanks!




Aucun commentaire:

Enregistrer un commentaire