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

161
Visualizações
Does an ajax request cause an asp.net session to be renew?

Have been working on detecting a timeout on an asp.net project. Have an ajax function that checks every 5 seconds to see if the session has expired. Without the ajax function checking, it actually expires after a minute, but if I keep the function on, it keeps sending me an "active" status. So I wonder, does my ajax function/request is keeping the session alive ?

Ajax function:

             function isSessionAlive(){
                await jQuery.ajax({
                type: "POST",
                url: 'coolpage.aspx/hello',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    console.info("status: ", response);
                },
                failure: function (response) {
                    console.info("status: ", response);
                },
                cache:false
            });}

Asp.net page method

    //[WebMethod(EnableSession = true)]
    [WebMethod]
    public static string hello()
    {
        //return (HttpContext.Current.Session["dummy"] == null) ? "expired" : "active";

        if (HttpContext.Current.Session != null)
        {
            if (HttpContext.Current.Session.IsNewSession)
            {
                string cookieHeader = HttpContext.Current.Request.Headers["Cookie"];
                if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
                {
                    return "expired";
                }
            }
        }

        return "active";

        // return HttpContext.Current.User.Identity.IsAuthenticated ?  "active":"expired";

    }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You have to use setInterval function in ajax.

setInterval(function(){
   $.get('coolpage.aspx/hello');
}, 300000); // 5mins
about 4 years ago · Juan Pablo Isaza Relatório

0

If your session has expired, so destroy your session and return "expired". After calling ajax(document.ready), you have to check your session value using if and else.

about 4 years ago · Juan Pablo Isaza 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