question

BinuThomas-0488 avatar image
0 Votes"
BinuThomas-0488 asked BinuThomas-0488 commented

Asp.net forms application- timeout and loosing data

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.

azure-ad-single-sign-ondotnet-aspnet-webpages
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered BinuThomas-0488 commented

Hi @BinuThomas-0488,
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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@LanHuang-MSFT Thank you.

this approach will keep the session open forever until they close the form. which will increase the server load.
is there a way to increase the timeout. I think login timeout is causing the problem. How can we increase login timeout for web form application with Office 365 authentication, cloud single sign on.

authentication mode is none in my web.config

<authentication mode="None">

0 Votes 0 ·