Interrupting POST request
I'm working on ASP.NET file uploader and currently trying to resolve the following issue: Assume at some moment the server side HttpModule decides that incoming data stream is too long and must be aborted. So the code that would handle this situation at first glance would be very simple. Like this:
try {
...
if (size >= maxSize)
throw new InvalidOperationException("File is too large!");
}
catch (InvalidOperationException e) {
HttpContext.Current.Response.Write(e.Message);
HttpContext.Current.Response.End();
return;
}
But unfortunately this does not work. Seems browser has not received the response and continues transferring data to server. Does anybody know why this does not work and how would be workaround?
Try calling Response.Close()
instead. This will immediately close the socket connection. You may need to call Response.Flush()
before hand.
精彩评论