Can IIS / ASP.NET abort an HTTP request when a client closes a connection?

Imagine that an HTTP request takes a long time to process in ASP.NET, and an impatient user refreshes the page several times. Now I have several copies of the same request, which makes it respond even slower.

I would like IIS to abort the thread if the client closes the connection while the request is still being processed. IIS can already abort the stream in timeout, but I want the stream to be canceled only if the client closed the connection.

I know that I could check Response.IsClientConnectedwhile the request is progressing, but that would be many checks scattered across hundreds of methods. I just want the thread to be automatically interrupted as soon as the client disconnects.

+4
source share
1 answer

The best way is to set the request / response limits for a few seconds, i.e. from 5 to 10 seconds. If the request does not give them the opportunity to try again. In addition, while the request is being served, press a busy progress bar or disappear on the screen for a better experience with the interface. This is what I did for one of my projects, and each user was so happy that now they know that the server is busy and will answer you soon.

0
source

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


All Articles