Set ASP.net executionTimeout in code / “refresh” request

I’ll have an ASP.net page that creates some Excel Sheets and sends them to the user. The problem is, sometimes I get Http timeouts, presumably because the Request runs longer than executionTimeout (110 seconds per default).

I just wonder what my options are to prevent this, without wanting to generally increase the executionTimeout in web.config?

In PHP, set_time_limit exists which can be used in a function to extend its life, but I did not see anything like that in C#/ASP.net?

How do you handle long-running functions in ASP.net?

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

If you want to increase the execution timeout for this one request you can set

HttpContext.Current.Server.ScriptTimeout

But you still may have the problem of the client timing out which you can’t reliably solve directly from the server. To get around that you could implement a “processing” page (like Rob suggests) that posts back until the response is ready. Or you might want to look into AJAX to do something similar.

Method 2

I’ve not really had to face this issue too much yet myself, so please keep that in mind.

Is there not anyway you can run the process async and specify a callback method to occur once complete, and then keep the page in a “we are processing your request..” loop cycle. You could then open this up to add some nice UI enhancements as well.

Just kinda thinking out loud. That would probably be the sort of thing I would like to do 🙂


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
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x