I have a identity validation problem I have a HTML and CSS I like to display for people logged in with a ticket number but whenever I start the application after I've closed it as a user logged in I always return as a logged in user with invalid ticket number.
<ul class="navbar-nav justify-content-end">
@if (HttpContext.Current.User.Identity.IsAuthenticated)
{
<li class="nav-item pt-4">
<a class="nav-link" aria-current="page" href="/mina-sidor/">Mina sidor</a>
</li>
<li class="nav-item pt-4">
@Html.ActionLink("Logga ut", "Logout", "Authentication", new { area = "" }, new { @class = "btn btn-primary" })
</li>
<li class="nav-item pt-4 px-1">
<p>Inloggad som <br /> <strong>@User.Identity.Name</strong></p>
</li>
}
else
{
<li class="nav-item pt-2">
@Html.ActionLink("Logga in", "Login", "Authentication", new { area = "" }, new { @class = "btn btn-primary" })
</li>
}
</ul>
HttpContext.Current.User.Identity.IsAuthenticated -> returns true always unless I manually log out.
I've tried Request.IsAuthenticated -> same here.
How do I handle that this return false when the website is closed or it has timed-out?
Have you a github or other repo to see your code?
Is the User.Identity.Name filled?
If your authentication system is based on cookie, exiting from the application the cookies aren't deleted/removed. So you need to verify if there are still there.
By default ASP.NET is configured for Session cookies. These cookies are not persistent and don't survive if you close your browser.
But if you have a persistent cookie with an expire time, like:
theCookie.Expires = DateTime.Now.AddHours(1);
your session will survive to browser closing action.
If your authentication system is based on Session storage or Persistent storage check it via F12 - Application - Storage data.