Exception Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/exception/ Microsoft Dynamics CRM . Microsoft Power Platform Fri, 24 Apr 2020 14:31:49 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/cropped-Microsoftdynamics365-blogs.png?fit=32%2C32 Exception Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/exception/ 32 32 176351444 Error : “Thread was being Aborted” Response.Redirect() and Server.Redirect () not working in code behind C# http://microsoftdynamics.in/2018/01/15/error-thread-was-being-aborted-response-redirect-and-server-redirect-not-working-in-code-behind-c/ Mon, 15 Jan 2018 06:56:00 +0000 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...

The post Error : “Thread was being Aborted” Response.Redirect() and Server.Redirect () not working in code behind C# appeared first on Microsoft Dynamics 365 Blog.

]]>

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

The post Error : “Thread was being Aborted” Response.Redirect() and Server.Redirect () not working in code behind C# appeared first on Microsoft Dynamics 365 Blog.

]]>
2751