Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set ASP.net executionTimeout in code / "refresh" request

Tags:

c#

asp.net

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?

like image 612
Michael Stum Avatar asked Aug 27 '08 07:08

Michael Stum


2 Answers

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.

like image 105
John Hunter Avatar answered Oct 21 '22 17:10

John Hunter


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 :)

like image 1
Rob Cooper Avatar answered Oct 21 '22 16:10

Rob Cooper