Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens in IIS/C# when a request is aborted

So I'm thinking about a functionality where the user pastes a link and the server-side code crawls the provided link and responds with the contents of that link (such as page title, description, thumbnail, etc).

The user can meanwhile change the link, and in doing that, the ajax-request should be aborted client-side.

I'm wondering what exactly happens in the IIS server and specifically to my C# code.

  • Is the response thread terminated?
  • Does the Response object now return null, or Response.Write throw exceptions?
  • Is an exception thrown in the response thread just whereaver it is? (that one doesn't even make sense, but whatever)
like image 336
bevacqua Avatar asked Jul 05 '12 18:07

bevacqua


2 Answers

If the server code checks the state of Response.IsClientConnected, it can stop the work and produce an empty response when the client aborts the request, otherwise it will just complete the request as usual.

The request handling will not be aborted automatically just because there is noone waiting for it any more. The server code has to actively check the state of the request.

like image 189
Guffa Avatar answered Oct 12 '22 23:10

Guffa


Your web server doesn't know that the client cancelled the request. The request will still be fulfilled and a response will be sent back. The client-side script that you write will need to be able to handle what the current state of your page should be.

If you are certain that you don't care about the response, I would recommend aborting the request client-side:

xhr.abort()
like image 28
Justin Helgerson Avatar answered Oct 13 '22 01:10

Justin Helgerson