0

I am getting this error message:

_message = "Thread was being aborted."

when I do

Response.Redirect("Default.aspx")

Can anyone help me?

missimer
  • 4,022
  • 1
  • 19
  • 33
  • 3
    Calling redirect triggers an exception which in turns causes the current thread to be aborted. This is normal ASP.NET behavior. – HashPsi Jul 31 '15 at 20:42

4 Answers4

0

This is normal behavior. See the documentation for this method. If you ever suspect something wrong with .NET, then always check MSDN first.

mason
  • 31,774
  • 10
  • 77
  • 121
0

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.

Community
  • 1
  • 1
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91
0

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.

Dacker
  • 892
  • 2
  • 8
  • 12
  • @ChristianJoséVallejo I think my answer also explains what the false does and that it's recommended by MSDN too. Don't understand how the answer without explanation which is posted 5 hours after mine is accepted as answer. I think my answer will help other users more. – Dacker Aug 01 '15 at 16:01
  • excuse me is my error, I'm very happy with your help, and help me so much to understand what happening – Christian José Vallejo Aug 02 '15 at 20:57
0

You need to send "false" along with the path on which you want to redirect user. Something like: Response.Redirect("Default.aspx", false);

Shilpa Soni
  • 2,034
  • 4
  • 27
  • 38