The problem is that the Response.End method throws a ThreadAbortException exception that prevents debugging.

The challenge is to avoid this exception.

The Response.Redirect ("nextpage.aspx", false) method Response.Redirect ("nextpage.aspx", false) will continue the further execution of the code, which is not acceptable in my case, as the 500-я error then drops.

How to get around this situation?

How to interrupt further code execution when calling the Response.Redirect("nextpage.aspx", false) method Response.Redirect("nextpage.aspx", false) ?

    1 answer 1

    No

    At the time of calling Response.End you are usually quite deep in the method call stack. Each of which can return something. The only way to exit the method without returning a value is to fly with an exception.

    Therefore, Response.End stops processing the request by throwing an exception that is caught higher on the code with a runtime and turns into a redirect.

    Those. You have only two options:

    • [Correct] Carefully return the result from all the methods to the controller itself. In the controller, return RedirectResult .
    • To mute catching exceptions with the studio when debugging - uncheck the stopbox checkbox on ThreadAbortException in Debug / Windows / Exceptions.

    The first option is preferable, because Otherwise, redirecting via Response.Redirect will provide you with subtle bugs from "cannot redirect after http-headers sent" if you randomly mix Response.Redirect and MVC RedirectResult .

    • one
      "with random mixing Response.Redirect and MVC-s RedirectResult" - and what should be done so that they are mixed? - Qwertiy
    • one
      @Qwertiy use only RedirectResult. They are usually mixed with Response.Redirect in the main code + RedirectResult somewhere in the filter, most often in the error handling filter. And instead of a normal exception, the log is written "could not redirect the user to the error page" :( - PashaPash
    • I didn’t have “no” in the question, but you answered him anyway :) - Qwertiy