Increase ASP.Net timeout on a per page level

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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.

Method 3

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();
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x