CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

Timeout of an ASP.NET page

In some cases it can take quite some time for the web server to complete your webpage. Setting a time out is not that difficult but Googling around you will either find over complicated scenarios or a very simple and clear story in Dutch. Before recapitulating that one in English I have to credit the author Michiel van Otegem. Besides writing some good content he's done a lot of work for the Dutch user group dotned. See him smiling here, he's the guy on the final picture.

The timeout for a page request depends whether you are running debug or release code. The setting is in the web.config. In debug mode the timeout is 30000000 seconds which is about a year. In release mode the timeout is only 90 seconds. In some cases that may not be enough. You cannot set the timeout as a property of the page itself; it is a property of the global Server object. Set it in the page init event and reset it in the page unload event.

        private int timeOut;

        private void KopierenJaar_Init(object sender, System.EventArgs e)

        {

            timeOut = Server.ScriptTimeout;

            // Give it 1 hour = 3600 seconds

            Server.ScriptTimeout = 3600;

        }

 

        private void KopierenJaar_Unload(object sender, System.EventArgs e)

        {

            Server.ScriptTimeout = timeOut;

        }

In case your page is doing heavy things in the database you have to set db timeouts as well. See here for a quick look at that.


Published Jun 15 2006, 08:31 AM by pvanooijen
Filed under:

Comments

Ayende Rahien said:

Just be sure to remember that this page is _not_ the only one that is running on the page.
And this mean that the same page running in parallel will very easily set the timeout _permenantly_ to whatever value you choose.
Generally a bad thing.
# June 15, 2006 12:45 PM

pvanooijen said:

Global is bad, it would have been better to have a property on the page.
The page unload will restore the value, so it's not a permanent change.
When you need a really long time it's better to do it in a new thread. Which has other drawbacks. More on that in an upcoming post.
# June 15, 2006 4:04 PM

Peter's Gekko said:

Another story from the app with the sprocs. That was a classical 2-tier CS application which we transformed...
# June 20, 2006 4:14 AM

Helios said:

Hello

There is some problem with the Server.ScriptTimeout  because, no matter what I do (on iis 6.0, on web.config, or in c# in many places of my code), every process stops exactly at 90secs, even more I defined in IIS 6.0 a 5000 secs timeout, and when within the code I ask for that value, it is 5000 as defined, but even so, the process stops at 90secs, and here is the incredible, no matter is if debug or release, where debug is suppoussed to stops in a year.

Really I do not know what to do, and for the application I made it is mandatory to use a very high value.

Helios
# July 25, 2006 3:33 PM

pvanooijen said:

As it's always 90 secs everywhere imho it looks like debugging is disabled. How and where to (re-)set that is beyond my knowledge. I would start with your machine.config.
# July 26, 2006 3:53 PM

Gerald said:

I decided to check the validity of this by writing a test program containing two pages.  In one of the pages I am setting the ScriptTimeout property to 3000, while in the other page the value of the property is not changed.  It turns out that after loading the first page, then the second page, the value of the ScriptTimeout in the second page is reverted to its default value (90 seconds for release, 30000000 for debug) or the value set in the configuration files.  In conclusion, the ScriptTimeout property, when changed in one page, does not change at a Global level.

# November 29, 2006 3:38 PM

pvanooijen said:

Thanks Gerald. Your experiment shows that Ayende's fear is not justified.

# November 30, 2006 1:44 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication

News