header1.html

Sunday, 21 September 2014

If you are monitoring errors of your application you might have noticed that in your error log file lots of 'Thread was being aborted' exception logged.
This Exception occurs when you use Response.Redirect inside of a Try / Catch block.
Your code will work and the browser will be redirected but that is reason of getting lots of alerts.If you are passing QueryString then your application may not work properly because of this issue, so it is important to handle or avoid this kind of exceptions.
There are different ways to resolve this issue,

Simplest way to move the Response.Redirect outside the Try/Catch block.

Catch Exception and do nothing,

try

{

if (Condition)

Response.Redirect("newpage.aspx”);

}

catch (ThreadAbortException ex)

{
// do nothing
}

catch (Exception e)

{
//Write your Error log logic
}

Use overload of Redirect method like,
Pass false as second parameter to this overload.
Response.Redirect("newpage.aspx”,false);

I prefer to use 3rd approach as it is easiest one to implement and it works fine in case if you are using QueryString in your application.

Follow This Blog !!!

About Me

Vote Me!!!

Disclaimer:

All content provided on this "Career Web Helper" blog is for informational purposes only.The Quizzes,Articles,Comments,opinions expressed is my personal views and does not related to my current or previous employers.The owner of http://sagarphalke.blogspot.in will not be liable for any errors or omissions in this information nor for the availability of this information.As this is my personal blog, I have full rights to modify, delete articles, content and other things without any prior notice to my subscribers ,users etc.Disclaimer and other policies are subject to change time to time and I have full rights to do that.