32

Is it possible to increase the timeout for a single ASP.net page. I know it is possible at the server level, but is it possible at thepage level?

I need this for a single report page that takes 2-3 minutes to load

any ideas?

ChrisCa
  • 10,876
  • 22
  • 81
  • 118
  • Increase the timeout? Do you mean *decrease* it? To increase the time taken by a page to load, you can always use Thread.Sleep (http://msdn.microsoft.com/en-us/library/d00bd51t.aspx). – Arseni Mourzenko Jun 24 '10 at 09:33

3 Answers3

35

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.

Mark Bell
  • 28,985
  • 26
  • 118
  • 145
  • Worked for me. I had to increate `maxRequestLength` as well to return a large file. It's in `Web.config`, section `system.web`, right next to the default ScriptTimeout: `` – Andomar Oct 04 '12 at 19:29
  • 3
    [This](http://stackoverflow.com/a/20901670/845584) suggests that ScriptTimeout is Classic ASP and `ExecutionTimeout` replaces it, however doesn't seem you can set the latter on a page-level, so it seems this a bit of legacy hack? (Also [here](http://stackoverflow.com/a/29754/845584)). – PeterX Mar 03 '15 at 07:50
21

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.

Community
  • 1
  • 1
Krishnan
  • 1,464
  • 15
  • 21
  • Does this also work for virtual paths like those from MVC apps or a OWIN middleware you register for a certain URL? – flq Oct 23 '15 at 09:00
  • Hmm... interesting question. It probably would, but I haven't tried it. At most, you would have to tweak the location path and/or the http hander and/or the router handler classes accordingly for it to work. Do let me know if anything worked out for you. Curious. – Krishnan Dec 09 '15 at 19:56
  • For anyone else wondering... executionTimeout="600" is 5 minutes. The parameter is in seconds. – Le-roy Staines Jun 19 '21 at 00:35
1

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();
}
Max Alexander Hanna
  • 3,388
  • 1
  • 25
  • 35