Saturday, June 11, 2011

ASP.NET setting a time out

Many times web server take time to complete processing. Setting a time out is not that difficult. The setting is in the web.config. Normal timeout is 90 seconds. We can use timeout; it is a property of the global Server object. It is better to set it in the page init event and reset it in the page unload event.

Here is sample code


private int timeOut;
private void Page_Init(object sender, System.EventArgs e)
{
timeOut = Server.ScriptTimeout;
// SET 1 hour = 3600 seconds
Server.ScriptTimeout = 3600;
}
private void Page_Unload(object sender, System.EventArgs e)
{
Server.ScriptTimeout = timeOut;
}