ASP.NET: What happens to code after Response.Redirect(…)?

前端 未结 4 1989
日久生厌
日久生厌 2021-02-03 18:31

Does Response.Redirect() cause the currently running method to abort? Or does code after Response.Redirect() execute also?

(That is, is it necessary to return/Exit Sub a

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-03 19:15

    This may not be a complete answer, but from what I've seen...

    Response.Redirect does, actually cause the code to stop executing by throwing a System.Threading.ThreadAbortException.

    You can see this for yourself by setting up global error handling in the Global.Asax and testing a Response.Redirect.

    EDIT

    and here is a link to the documentation that supports my answer:

    Redirect calls End which raises a ThreadAbortException exception upon completion.

    HttpResponse.Redirect Method (String, Boolean) (System.Web)

提交回复
热议问题