Please wait, loading...

 

Error : “Thread was being Aborted” Response.Redirect() and Server.Redirect () not working in code behind C#

January 15, 2018

Error : “Thread was being Aborted”

InnerException : null

Message : Thread was being aborted”

Source : Unable to evaluate expression because the code is optimised or a native frame is on top of the call

Stack trace :  at System.Threading.Thread.AbortInternal()
   at System.Threading.Thread.Abort(Object stateInfo)
   at **.Response.Page_Load(Object sender, EventArgs e) in C:Users**documentsvisual studio 2015Projects****Response.aspx.cs:line 87

try {
Response.Redirect(redirectionURl);
 }
catch (Exception ex){
Response.Redirect(redirectionURl);
}

Resolution 

Response.Redirect Method[^] when called with just one parameter would throw ThreadAbortException. You should pass false as the second parameter and then complete the request. Quoting from the link mentioned above:

MSDN HttpResponse.Redirect Method :
When you use this method in a page handler to terminate a request for one page and start a new request for another page, set endResponse to false and then call the CompleteRequest method. If you specify true for the endResponse parameter, this method calls the End method for the original request, which throws a ThreadAbortException exception when it completes. This exception has a detrimental effect on Web application performance, which is why passing false for the endResponse parameter is recommended

try {
Response.Redirect(redirectionURl,false);
 }
catch (Exception ex){
}
Hope it helps !!

Happy Coding 😊

SOURCE : mscrm.com

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651
Microsoft Dynamics Community Profile

Learn more