Is there something that prevents Response.Redirect to work inside try-catch block?

前端 未结 5 1211
旧时难觅i
旧时难觅i 2020-12-10 06:05

I got some weird error with response.redirect() and the project wasn\'t building at all.. when I removed the try-catch block that was surrounding the b

5条回答
  •  有刺的猬
    2020-12-10 06:49

    If I remember correctly, Response.Redirect() throws an exception to abort the current request (ThreadAbortedException or something like that). So you might be catching that exception.

    Edit:

    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.

提交回复
热议问题