try catch中使用Response.End()
来源:互联网 发布:java 手机验证码 编辑:程序博客网 时间:2024/05/21 02:39
A.
如果使用 Response.End、Response.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常。异常内容:由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值
您可以使用 try-catch 语句捕获此异常。
Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 Response.End
解决方案 :• 对于 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 以跳过 Application_EndRequest 事件的代码执行。
• 对于 Response.Redirect,请使用重载 Response.Redirect(String url, bool endResponse),该重载对 endResponse 参数传递 false 以取消对 Response.End 的内部调用。例如:
Response.Redirect ("nextpage.aspx", false);
B.
在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作。
如果将Response.End()放在try...catch中,catch会捕捉Thread.CurrentThread.Abort()产生的异常System.Threading.ThreadAbortException。
解决方法(任选一个):
在catch中排除ThreadAbortException异常,示例代码如下:
try{ Response.End();}catch (System.Threading.ThreadAbortException){}catch (Exception ex){ Response.Write(ex);}
用Context.ApplicationInstance.CompleteRequest()结束当前请求,代码如下:
protected void Page_Load(object sender, EventArgs e){ try { Response.Write("Hello world!"); this.Page.Visible = false; Context.ApplicationInstance.CompleteRequest(); } catch (Exception ex) { Response.Write(ex); }
- try catch中使用Response.End()
- try catch中使用Response.End()
- try-catch 与 Response.End()
- try...catch与Response.End()
- try...catch与Response.End()
- try catch语句中执行条件判断使用response.end时提示thread abort错误的解决方案
- MATLAB中try...catch...end的用法
- matlab try...catch...end
- MATLAB中关于try...catch...end的用法
- MATLAB: try-catch-end用法
- asp.net 在使用Response.Redirect try{}catch{}块失效
- asp.net 在使用Response.Redirect try{}catch{}块失效
- pb 的try catch finally end try
- 2005中能够使用Try...Catch语句
- SQLServer2005中能够使用Try...Catch语句
- java中try 与catch的使用
- java中try 与catch的使用
- java中try 与catch的使用
- SQL中IN和EXISTS用法的区别
- 基于JDBC的数据库连接池技术研究与应用
- Wiz为知 - 简洁实用的知识笔记管理软件
- eclipse下httpservlet类用不了
- linux内核编译笔记
- try catch中使用Response.End()
- PHP相关系列 - 商品秒杀库存问题
- rpm命令
- 线程中sleep 与interrupt方法的应用
- plsql 导入dmp表(全量导入)
- VBS在AD中查询用户信息
- 关于thinkphp中文乱码的问题,新版的没有出GBK版,美中不足啊。
- 由于这台计算机没有终端服务器客户端访问许可证无法远程-解决!
- hdu1026