Increase ASP.Net timeout on a per page level

Ive found my problem was resolved by increasing the SQL timeout, using command.CommandTimeout = 100; example:

using (var connection = new SqlConnection(connectionString)) 
{
  connection.Open();
  SqlCommand command = new SqlCommand(queryString, connection);
  // Setting command timeout to 100 seconds
  command.CommandTimeout = 100;
  command.ExecuteNonQuery();
}

I think what you're looking for is ScriptTimeout. You can set this in-page like this:

Page.Server.ScriptTimeout = 60;

The timeout value is in seconds.

Also, be aware of the fact that if you are running in debug mode, this gets ignored and the timeout is set to the maximum; I don't think that's an issue for you anyway though, as you're increasing the timeout, not decreasing it.


As per this page, and I could verify too, another good way to achieve this is to add this to your config's configSection:

  <location path="~/MyPage.aspx">
    <system.web>
      <httpRuntime executionTimeout="600"/>      
    </system.web>    
  </location>

You could then also add other attributes like maxRequestLength="204800" or other sections, like:

  <location path="~/MyPage.aspx">
    <system.web>
      <httpRuntime executionTimeout="6000" maxRequestLength="204800" />      
    </system.web>    
    <system.webServer>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="209715200" />
        </requestFiltering>
      </security>
    </system.webServer>
  </location>

Hope this helps.