If you want to extend the amount of time permitted for an ASP.NET script to execute then increase the Server.ScriptTimout
value. The default is 90 seconds.
For example:
// Increase script timeout for current page to five minutes
Server.ScriptTimeout = 300;
This value can also be configured in your web.config
file in the httpRuntime
configuration element:
<!-- Increase script timeout to five minutes -->
<httpRunTime executionTimeout="00:05:00
... other configuration attributes ...
/>
If you've already done this but are finding that your session is expiring then increase the
ASP.NET HttpSessionState.Timeout
value:
For example:
// Increase session timout to thirty minutes
Session.Timout = 30;
This value can also be configured in your web.config
file in the sessionState
configuration element:
<configuration>
<system.web>
<sessionState
mode="InProc"
cookieless="true"
timeout="30" />
</system.web>
</configuration>
If your script is taking several minutes to execute and there are many concurrent users then consider changing the page to an Asynchronous Page. This will increase the scalability of your application.
The other alternative, if you have administrator access to the server, is to consider this long running operation as a candidate for implementing as a scheduled task or a windows service.