I am getting this error message:
_message = "Thread was being aborted."
when I do
Response.Redirect("Default.aspx")
Can anyone help me?
I am getting this error message:
_message = "Thread was being aborted."
when I do
Response.Redirect("Default.aspx")
Can anyone help me?
This is normal behavior. See the documentation for this method. If you ever suspect something wrong with .NET, then always check MSDN first.
Similar question:
Is Response.End() considered harmful?
Per Mason's link: "Redirect calls End which throws a ThreadAbortException exception upon completion."
Instead of response.End() which correctly raises an exception, I think the following might fix the problem:
// Prevents any other content from being sent to the browser
response.SuppressContent = True;
// Directs the thread to finish, bypassing additional processing
HttpContext.Current.ApplicationInstance.CompleteRequest();
We’re not looking at the bigger picture here of why this keeps happening:
(1) We should never be calling the End() method on the Response object in the first place. Only reason this is still part of the current API is for compatibility with old ASP.
(2) When we call End(), I believe we are killing the same process that the Web form is running in, which is why Microsoft raises the exception in the first place.
You can do the following:
Response.Redirect("Default.aspx", false);
return;
This doesn't end the response, so no ThreadAbortException is thrown. Calling return makes sure no following logic is executed unnecessarily.
The msdn link https://msdn.microsoft.com/en-us/library/a8wa7sdt(v=vs.110).aspx says the following:
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.
You need to send "false" along with the path on which you want to redirect user. Something like: Response.Redirect("Default.aspx", false);