Click here to Skip to main content
13,667,677 members
Rate this:
Please Sign up or sign in to vote.
See more:
Exception Message : Thread was being aborted.

I am getting above exception when running the application in prod server. I never get that exception in dev and in test environment. 
Could any please help me out. If there is anything wrong in the code. 

My code in vb.

                    Dim filePath As String = Request.QueryString("fn")
                    Response.ContentType = ContentType
                    Response.AppendHeader("content-disposition", "attachment; filename=" + Path.GetFileName(filePath))

                    If File.Exists(filePath) Then
                    End If

                Catch ex As Exception
                    oUtility.WriteLog("Exception Message : " + ex.Message, True)
                    vm.stat = 2
                    vm.message = "Internal server error"
                End Try

My code in C#

  string filePath = Request.QueryString["fn"];
                        Response.ContentType = ContentType;
                        Response.AppendHeader("content-disposition", "attachment; filename=" + Path.GetFileName(filePath));

                        if (File.Exists(filePath))

What I have tried:

I tried to run the application in dev environment. I never got that issue. I could not reproduce the error.
Posted 12-Oct-17 8:32am
Updated 12-Oct-17 9:17am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is by design:
To mimic the behavior of the End method in ASP, this method tries to raise a ThreadAbortException exception. If this attempt is successful, the calling thread will be aborted, which is detrimental to your site's performance. In that case, no code after the call to the End method is executed.

Remove the Response.End() call, and replace it with Application.CompleteRequest(), as suggested in the documentation.

HttpApplication.CompleteRequest Method (System.Web) | Microsoft Docs[^]
s23user 12-Oct-17 21:06pm
Sir, real issue is, as you could see above code is to download the file passed in query string. we have two server in prod. and load balancer. in prod while we call the code to download the file, It does not get downloaded and in log file i get that message as exception. So could you tell me what could have gone wrong? looking at the code. In dev environment i never had this issue.
Richard Deeming 13-Oct-17 7:50am
Read my answer again. If you call Response.End, you will get a ThreadAbortException.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180820.1 | Last Updated 12 Oct 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100