Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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 answers
Answer question

0

You have to use setInterval function in ajax.

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

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!