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

守給你的承諾、 提交于 2019-11-30 08:27:58

Yes, this is indeed by design. Microsoft has even documented it. How else would you stop the rest of your program from execution?

There is no such thing as a "graceful" abort. You could simply Flush() the response, though, instead of ending it and let the framework take care of closing the connection for you. I'm assuming in this case that you want the response sent to the client, i.e., the typical case.

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

There's nothing inherently ungraceful about an exception recursing up your stack to stop the current execution. Certainly no more than you throwing an exception and catching it at some lower place in your exception.

I'd look at filtering it from your logging. If you're using the ASP.Net health monitoring you can configure/map each exception to a given provider (event log, mail, etc) to control whether you get a notification for threadabort exceptions or not. If it's custom logging then I'd just add an if to check for it.

Note that you can't eat a ThreadAbortException so even if your logging code is doing something like catch(Exception e) { // log exception and then do not throw again } the ThreadAbortException will still be raised again by the framework once your catch block exits.

Don't use Response.End() method because it uses Application.End() and stop the application. Further use HTTP request or response violating Page Life Cycle. Use HttpContext.Current.Response.Close() or HttpContext.Current.ApplicationInstance.CompleteRequest();

I used all above changes but still I was getting same issue on my web application.

Then I contacted my hosting provide & asked them to check if any software or antivirus blocking our files to transfer via HTTP. or ISP/network is not allowing file to transfer.

They checked server settings & bypass the "Data Center Shared Firewall" for my server & now our application started to download the file.

Hope this answer will help someone.This is what worked for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!