Currently tackling a timeout detection issue in an asp.net project. I've implemented an ajax function that checks every 5 seconds to determine if the session has expired. Interestingly, without the ajax function running, the session actually times out after a minute. However, with the function active, it continuously sends an "active" status. This makes me question whether my ajax function is responsible for 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";
}