How to set IHttpAsyncHandler timeout?

I tried setting executeTimeout in the web.config file:

<compilation debug="false" targetFramework="4.5"> <httpRuntime executionTimeout="30"/> 

After looking at the IIS Manager Requests page, I see that the requests do not stop after 30 seconds.
Should I use a timer inside my IHttpAsyncHandler?

+6
source share
3 answers

With the obvious lack of built-in support for IHttpAsyncHandler timeouts, you should probably manage your timeout. Perhaps this is by design; because you choose an asynchronous template - who does MSFT, thinking that they are trying to set a default timeout for your long-term task?

What I would do is use ThreadPool.RegisterWaitForSingleObject to control your poll with an appropriate timeout. Here is an example of the code that I use to avoid waiting for a web service that never returns:

 private const int REQUEST_TIMEOUT = 30000; // miliseconds (30 sec) private void CallService() { try { string url = "somewebservice.com"; WebRequest request = WebRequest.Create(url); // Asynchronously fire off the request IAsyncResult result = request.BeginGetResponse(new AsyncCallback(MyRoutineThatUsesTheResults), request); // Handle timed-out requests ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(RequestTimeout), request, REQUEST_TIMEOUT, true); } catch (Exception ex) { _logger.Error("Error during web service request.", ex); } private void RequestTimeout(object state, bool timedOut) { if (timedOut) { WebRequest request = (WebRequest)state; _logger.WarnFormat("Request to {0} timed out (> {1} sec)", request.RequestUri.ToString(), REQUEST_TIMEOUT / 1000); request.Abort(); } } 

You will need IAsyncResult to work with this approach, but with the template installed, you should have no problem running the samples.

In addition, you will encounter problems when IIS decides to recycle your application pool / disconnect your application domain while your survey is still running. If this is you want to process, you can use HostingEnvironment.RegisterObject .

+4
source

You can try adding this to your web.config file:

 <system.web> <pages asyncTimeout="30" /> </system.web> 

Its for PageAsyncTask , but can it also be done for IHttpAsyncHandler too?

If not, you might be lucky with the new version of HttpTaskAsyncHandler in ASP.Net 4.5: http://www.asp.net/vnext/overview/whitepapers/whats-new#_Toc318097378

0
source

You will need to use RegisterAsyncTask to check the link below.

http://msdn.microsoft.com/en-us/magazine/cc163725.aspx

-1
source

Source: https://habr.com/ru/post/916400/


All Articles