Reputation: 218722
I am getting a " Thread was being aborted " Exception in an ASP.NET page.I am not at all using any Response.Redirect/Server.Transfer method.Can any one help me to solve this ?
Upvotes: 1
Views: 5469
Reputation: 6149
Error: Thread was being aborted. at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End()
This error occurs mainly If You Use Response.End, Response.Redirect, or Server.Transfer
Cause: The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application’s event pipeline. The line of code that follows Response.End is not executed.
This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.
Resolution/Solution:
You can use a try-catch statement to catch this exception
or
For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event. For Response.Redirect, use an overload, Response.Redirect(String url, bool endResponse) that passes false for the endResponse parameter to suppress the internal call to Response.End. For example: ex: Response.Redirect (“nextpage.aspx”, false); If you use this workaround, the code that follows Response.Redirect is executed. For Server.Transfer, use the Server.Execute method instead.
Upvotes: 0
Reputation: 27265
The bad solution is using
Response.Redirect(URL, False)
which will cause not to Response.End() current page, however be careful this might lead problems because rest of the page will get executed and might cause login bypass and similar security and performance issues.
Edit : Apparently you are not using Response.Redirect and you can't catch AbortThreadExecution with Try Catch, which means this answer is totally useless now :)
Although to able to get an answer you need to learn how to ask a question. you need to provide information such as :
Upvotes: 1
Reputation: 35196
This can happen if the web app is being shut down or forcefully restarted while your code executes. I have seen this happen when your web app writes files to the web directory in which it's hosted, causing a recompile of the web app.
Upvotes: 1