When ASP.NET System.Web.HttpResponse.End () is called, is the current thread interrupted?

when System.Web.HttpResponse.End () is called System.Thread.Abort fired, which I assume is throwing (or throwing) an exception? I have some entries and this appears in the log file ...

First chance

exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll 12/14/2008 01:09:31:: Error in Path :/authenticate Raw Url :/authenticate Message :Thread was being aborted. Source :mscorlib Stack Trace : at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at DotNetOpenId.Response.Send() at DotNetOpenId.RelyingParty.AuthenticationRequest.RedirectToProvider() at MyProject.Services.Authentication.OpenIdAuthenticationService.GetOpenIdPersonaDetails(Uri serviceUri) in C:\Users\Pure Krome\Documents\Visual Studio 2008\Projects\MyProject\Projects\Services\Authentication\OpenIdAuthenticationService.cs:line 108 at MyProject.Mvc.Controllers.AuthenticationController.Authenticate() in C:\Users\Pure Krome\Documents\Visual Studio 2008\Projects\MyProject\Projects\MVC Application\Controllers\AuthenticationController.cs:line 69 TargetSite :Void AbortInternal() A first chance exception of type 'System.Threading.ThreadAbortException' occurred in Ackbar.Mvc.DLL An exception of type 'System.Threading.ThreadAbortException' occurred in Ackbar.Mvc.DLL but was not handled in user code 

Is this normal behavior and is it possible to gracefully interrupt instead of (what looks like) a sudden sudden interruption?

Update

While this is a general census, it is by design . So I'm wondering if it’s possible, we could take this question and see if we can change the code so that it doesn’t feel that we are ending the stream prematurely and gracefully exit ... Maybe? Code examples?

+18
thread-abort
Dec 13 '08 at 14:15
source share
5 answers

Yes, it is really by design. Microsoft has even documented it. How else will you stop the rest of your program?

+6
Dec 13 '08 at 14:41
source

There is no such thing as a graceful interruption. You could just reset () the answer, but instead of ending it, and let the structure take care to close the connection for you. In this case, I assume that you want to receive a response sent to the client, i.e. A typical case.

According to MSDN, calling Response.End () throws a ThreadAbortException when the response ends prematurely. You really should only call Response.End () when you want the exception raised.

+11
Dec 13 '08 at 14:36
source

Nothing is justifiable from the start regarding the exception returning your stack to stop the current execution. Of course, no more than you throw an exception and catch it in some lower place in your exception.

I would look at its filtering from the log. If you use ASP.Net health monitoring, you can configure / map each exception to this provider (event log, mail, etc.), to control whether or not an exception notification is received in the streaming channel. If this is custom logging, I'll just add an if to test it.

Note that you cannot have a ThreadAbortException, so even if your logging code does something like catch(Exception e) { // log exception and then do not throw again } , ThreadAbortException will still be thrown by the framework after exiting of your catch block.

+3
Dec 13 '08 at 18:37
source

Do not use the Response.End () method, because it uses Application.End () and stops the application. Continued use of an HTTP request or response that violates the page life cycle. Use HttpContext.Current.Response.Close () or HttpContext.Current.ApplicationInstance.CompleteRequest ();

0
Jun 06 '17 at 11:31 on
source

I used all of the above changes, but still I had the same problem in my web application.

Then I contacted my hosting and asked them to check if any software or antivirus is forbidden to block our files via HTTP. or ISP / network does not allow file transfer.

They checked the server settings and bypassed the "General data center firewall" for my server, and now our application began to download the file.

Hope this answer helps someone. This is what worked for me

0
Nov 13 '17 at 4:06 on
source



All Articles