Why Response.Redirect causes System.Threading.ThreadAbortException?

前端 未结 10 1822
误落风尘
误落风尘 2020-11-22 15:00

When I use Response.Redirect(...) to redirect my form to a new page I get the error:

A first chance exception of type \'System.Threading.ThreadAbortEx

10条回答
  •  -上瘾入骨i
    2020-11-22 15:37

    Response.Redirect() throws an exception to abort the current request.

    This KB article describes this behavior (also for the Request.End() and Server.Transfer() methods).

    For Response.Redirect() there exists an overload:

    Response.Redirect(String url, bool endResponse)
    

    If you pass endResponse=false, then the exception is not thrown (but the runtime will continue processing the current request).

    If endResponse=true (or if the other overload is used), the exception is thrown and the current request will immediately be terminated.

提交回复
热议问题