zoukankan      html  css  js  c++  java
  • asp.net 在使用Response.Redirect try{}catch{}块失效

     

    try
    {


    Response.Redirect(
    "/mymaimai.aspx");

    }
    catch (Exception e)
    {
    //
    异常处理

    }


    使用以上语句,不管是否有异常,都会执行catch中的,一直显示""失败"",都会抛出System.Threading.ThreadAbortException,原因如下
    :
    Response.End 
    方法停止页的执行,并将该执行变换到应用程序的事件管线中的 Application_EndRequest 事件。 Response.End 后面的代码行将不执行。
     
    此问题出现在 Response.Redirect  Server.Transfer 方法中,这是由于这两种方法都在内部调用 Response.End
     
    解决方案

    若要解决此问题,请使用下列方法之一:
     
    对于 Response.End,调用 ApplicationInstance.CompleteRequest 方法而不调用 Response.End,以便跳过 Application_EndRequest 事件的代码执行。
     
    对于 Response.Redirect,使用重载 Response.Redirect(String url, bool endResponse),对 endResponse 参数它传递 false以取消对 Response.End 的内部调用。例如:
     
       Response.Redirect (
    "/mymaimai.aspx", false);如果使用这种解决方法,Response.Redirect 后面的代码将得到执行。
     
    对于 Server.Transfer,请改用 Server.Execute 方法。
     
    状态

    这种现象是设计使然。

    解决后的代码
    :
    try
    {
    Response.Redirect(
    "/mymaimai.aspx"
    ,false);
    }
    catch 
    {
    //
    异常处理

    }
  • 相关阅读:
    C++开源库
    Boost ASIO proactor 浅析
    ehcache
    http://www.servicestack.net/
    hortonworks
    (总结)Nginx 502 Bad Gateway错误触发条件与解决方法
    VMware vSphere虚拟化学习手册下部
    精确字符串匹配(BM算法) [转]
    Linux下基本TCP socket编程之服务器端
    How To Use Linux epoll with Python
  • 原文地址:https://www.cnblogs.com/jkswjw/p/1403639.html
Copyright © 2011-2022 走看看