locked
Response.Redirect to change page RRS feed

  • Question

  • User546194788 posted

    I asp.net project, I use Response.Redirect to change page.

    When do need to add "False/Ture" after url?

    For example, I want to change  to order.aspx from default.aspx, which code is correct?

    Response.Redirect("order.aspx", false)

    Response.Redirect("order.aspx", true)

    Response.Redirect("order.aspx")

    Wednesday, November 28, 2018 6:40 PM

All replies

  • User475983607 posted

    I asp.net project, I use Response.Redirect to change page.

    When do need to add "False/Ture" after url?

    For example, I want to change  to order.aspx from default.aspx, which code is correct?

    Response.Redirect("order.aspx", false)

    Response.Redirect("order.aspx", true)

    Response.Redirect("order.aspx")

    Please read the openly published documentation for an explanation with code examples.

    public void Redirect (string url, bool endResponse);

    https://docs.microsoft.com/en-us/dotnet/api/system.web.httpresponse.redirect?view=netframework-4.7.2

    If endResponse is true the current page execution is terminated and a redirect response is sent to the browser.  False allow the page to logic to continue until the natural end of the response.  Use false if you wish to execute logic after the Response.Redirect() line.

    Wednesday, November 28, 2018 6:51 PM
  • User546194788 posted

    Before I always use code below, is it false or true?

    Response.Redirect("order.aspx")

    I did not receive any warning message until recently got 

    System.Threading.ThreadAbortException: Thread was being aborted

    Wednesday, November 28, 2018 7:06 PM
  • User475983607 posted

    Before I always use code below, is it false or true?

    Response.Redirect("order.aspx")

    The linked documentation explains this...  endResponse defaults to true.

    Calling Redirect is equivalent to calling Redirect with the second parameter set to true.

    Wednesday, November 28, 2018 7:10 PM
  • User546194788 posted

    Thank you.

    The reason asking this question because I got the warning message when I published update apps.

    System.Threading.ThreadAbortException: Thread was being aborted

    I searched in google.com and some people recommend that adding "false" as second parameter.

    I'll try it.

    Wednesday, November 28, 2018 7:24 PM
  • User475983607 posted

    aspfun

    Thank you.

    The reason asking this question because I got the warning message when I published update apps.

    System.Threading.ThreadAbortException: Thread was being aborted

    I searched in google.com and some people recommend that adding "false" as second parameter.

    I'll try it.

    Correct, this is a known issue when you add a try...catch around a Response.Redirect.  The openly published documentation explain this error clearly and openly. 

    Redirect calls End which throws a ThreadAbortException exception upon completion. This exception has a detrimental effect on Web application performance. Therefore, we recommend that instead of this overload you use the HttpResponse.Redirect(String, Boolean) overload and pass false for the endResponse parameter, and then call the CompleteRequest method. For more information, see the End method.

    Secondly, just adding false might fix the error but could cause other errors as explained in my initial thread the the docs.  

    Is there some reason why you are not reading the reference docs or my posts?

    Wednesday, November 28, 2018 7:50 PM