Asp.net forms application- timeout and loosing data

Binu Thomas 171 Reputation points
2021-10-27T16:32:14.243+00:00

Hi All,

I have a small application for all staff to enter their project information. I created it with ASP.NET forms application - Office 365 authentication, cloud single sign on.

Normally employees take minimum 1 hour to fill the form, by the time application is getting timeout and going for office 365 reauthentication and users are loosing data. users are irritated because of this behavior.

I have done below

In the IIS server Application pool idle timeout - 150
in web. config
<httpRuntime targetFramework="4.6.1" executionTimeout="360000"/>
<sessionState timeout="360000"></sessionState>

I have tried auto save on text changed, but this will work if the users are active only, if they keep the session open and come back after 30 minutes it will not work

Any help to resolve this issue.

Microsoft Security Microsoft Entra Microsoft Entra ID
Developer technologies ASP.NET Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2021-10-28T06:27:19.363+00:00

    Hi @Binu Thomas ,
    First, there is a problem. The unit of executionTimeout is seconds, and the unit of HttpSessionState.Timeout is minutes.
    On way of to solve your problem is to keep session alive while the form is opened.
    First, create a generic handler and enter code as below:

    using System;  
    using System.Collections.Generic;  
    using System.Diagnostics;  
    using System.Globalization;  
    using System.IO;  
    using System.Linq;  
    using System.Reflection;  
    using System.Runtime.CompilerServices;  
    using System.Security;  
    using System.Text;  
    using System.Threading.Tasks;  
    using Microsoft.VisualBasic;  
      
    public class KeepSessionAlive : IHttpHandler, IRequiresSessionState  
    {  
        public void ProcessRequest(HttpContext context)  
        {  
            context.Session("KeepSessionAlive") = DateTime.Now;  
        }  
      
        public bool IsReusable  
        {  
            get  
            {  
                return false;  
            }  
        }  
    }  
    

    Make sure your generic handler class implements IRequiresSessionState as above.
    Then in you form page, use jQuery.post to post request the above handler at time interval of you choice. For example:

    <script type="text/javascript">  
        $(function () {  
            setInterval(function () { $.post('<%= ResolveClientUrl("~/KeepSessionAlive.ashx")%>'); }, 10000); ' 10 secs interval  
            });  
    </script>  
    

    While user is on the form, the POST requests will keep refreshing user's session just like normal page requests and therefore, IIS will keep on reseting the session timeout.
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.