Peter's Gekko

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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.


Posted Thu, Jun 15 2006 8:31 AM by pvanooijen
Filed under:

[Advertisement]

Comments

Ayende Rahien wrote re: Timeout of an ASP.NET page
on Thu, Jun 15 2006 12:45 PM
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.
pvanooijen wrote re: Timeout of an ASP.NET page
on Thu, Jun 15 2006 4:04 PM
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.
Peter's Gekko wrote A long running SQL batch in asp.net with feedback
on Tue, Jun 20 2006 4:14 AM
Another story from the app with the sprocs. That was a classical 2-tier CS application which we transformed...
Helios wrote re: Timeout of an ASP.NET page
on Tue, Jul 25 2006 3:33 PM
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
pvanooijen wrote re: Timeout of an ASP.NET page
on Wed, Jul 26 2006 3:53 PM
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.
Gerald wrote re: Timeout of an ASP.NET page
on Wed, Nov 29 2006 3:38 PM

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.

pvanooijen wrote re: Timeout of an ASP.NET page
on Thu, Nov 30 2006 1:44 AM

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

vinay ashar wrote re: Timeout of an ASP.NET page
on Tue, Sep 9 2008 1:35 AM

Bingo!!!!!!!!!!!

It works for me....

thanx buddy

Ben wrote re: Timeout of an ASP.NET page
on Tue, Sep 23 2008 9:36 AM

You should update your CSS for us firefox users!

This does the trick for me:

.CommentArrow {position:relative;top:2px}

System.Reflection.Emit wrote Quick Tip: Invoke A URL From SQL Server Agent
on Sat, Oct 11 2008 3:07 PM

Quick Tip: Invoke A URL From SQL Server Agent

Ranjit Singh wrote re: Timeout of an ASP.NET page
on Tue, Oct 14 2008 12:38 AM

Working Fine. But The Comments can not be ignorted for this article. can we do so with .ashx file which can work independent of rest of form. ?

Please Let Me Know If yes.

Thanks

pvanooijen wrote re: Timeout of an ASP.NET page
on Thu, Nov 13 2008 4:44 PM

Why would an ashx be different ? After all it's just another request longing for a response. You want to know for real ? Run a test !

Chris Hynes wrote re: Timeout of an ASP.NET page
on Sun, Jan 4 2009 11:00 AM

The Server.Timeout property actually sets the (for some unbeknowst reason internal) HttpContext.Timeout property, so there is no reason to worry about threading, concurrency, or global change issues.

Maria wrote re: Timeout of an ASP.NET page
on Tue, Jan 13 2009 8:54 AM

Hi Geek,

Can some pls help me in this problem ?

My Web application has timeout set to 90 sec(which is default) and the DB commandtimeout  changed to 90 sec (default is 30 sec) , if my application runs more than 90 sec i get the Timout error from DB, so i increased the DB timeout to 200 sec, now the query works fine, but what is the purpose of the web request timeout which is 90 sec ?

Actally speaking when the request takes more than 90 sec it shd through me an error ? right ?

Note : The application is publised and not in debuig mode.

pvanooijen wrote re: Timeout of an ASP.NET page
on Tue, Jan 13 2009 9:08 AM

Hi Maria,

did you check this :

codebetter.com/.../141459.aspx

Surya Narayan Behera wrote re: Timeout of an ASP.NET page
on Mon, Feb 9 2009 12:30 AM

How to handle the Server Time out  Error in asp.net with VB

pvanooijen wrote re: Timeout of an ASP.NET page
on Tue, Feb 10 2009 3:50 AM
b2b wrote re: Timeout of an ASP.NET page
on Sun, Jun 14 2009 8:56 AM

what about @page directive?

HugoZ wrote re: Timeout of an ASP.NET page
on Fri, Aug 14 2009 12:16 PM

The changes to the Global.asax file are not being applied, what do we need to do in order to refresh the setting?

Add a Comment

(required)  
(optional)
(required)  
Remember Me?