We have an asp.net application which uses
1) In proc sessionstate management and
2) Forms authentication
Both the session state and forms authentication timeouts have been set to 20 minutes. Forms authentication has been set to sliding expiration true.
<system.WebServer>
<handlers>
<remove name="KeepAlive" />
<add name="KeepAlive" verb="GET" path="AJAXKeepAlive.ashx"
type="IRCoder.AJAXKeepAlive" preCondition="integratedMode"/>
</handlers>
</system.WebServer>
<authentication mode="Forms">
<forms name=".Auth" loginUrl="Login.aspx" slidingExpiration="true"
protection="All" timeout="20"></forms>
</authentication>
<sessionState cookieName="ssid" mode="InProc" cookieless="false" timeout="20"/>
I have a keep alive handler which is called on the master page every page refresh.
public class AJAXKeepAlive : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Session["KeepAlive"] = DateTime.Now;
}
public bool IsReusable
{
get
{
return false;
}
}
}
In Master page:
$.get("<%=ResolveUrl("~/")%>AJAXKeepAlive.ashx");
Problem: When am debugging in my local using visual studio iis express, session_end method in global.asax.cs is always called at the end of 20 minutes automatically even when am refreshing the page several times.
My assumption is that when I make a trip to the server/IIS session timer will be reset and it will only expire when there is 20 minutes of inactivity. This is not the case. I have been very active on the site but still the session_end method is called.
Things I've tried:
I've hosted the application on IIS in our dev server. I have set the IIS session timeout property to be 30 minutes. I have also updated the IIS application pool Idle Time-out minutes to be 30 minutes.
Even in this case, session ends in 20 minutes.
I am unable to have the session slide as it normally should after every page request. Any pointers here is much appreciated.
Solution/Edit:
After researching for a long time, we found that the regeneration of session id while the user is logging in is causing the problem.
Further Update:
I was able to resolve this issue completely. Please use the c# code in the link below: https://stackoverflow.com/a/56391868/3189880 There are other answers in that page but the one that works is the one where the oldId is removed rather than the releasing it. Again only remove the item from store but not release it.