Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
How to check the logged in users session and if they are logged in authenticated?

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?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda