Why Response.Redirect causes System.Threading.ThreadAbortException?

前端 未结 10 1869
误落风尘
误落风尘 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条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 15:29

    The correct pattern is to call the Redirect overload with endResponse=false and make a call to tell the IIS pipeline that it should advance directly to the EndRequest stage once you return control:

    Response.Redirect(url, false);
    Context.ApplicationInstance.CompleteRequest();
    

    This blog post from Thomas Marquardt provides additional details, including how to handle the special case of redirecting inside an Application_Error handler.

提交回复
热议问题