终止线程 Response.End 在Asp.net 里面的正确使用
来源:互联网 发布:flash player修复软件 编辑:程序博客网 时间:2024/04/20 07:40
PRB:在使用 Response.End、Response.Redirect 或 server.Transfer 时出现 ThreadAbortException
症状
如果使用 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);
如果使用此替代方法,将执行 Response.Redirect 后面的代码。
• 对于 Server.Transfer,请改用 Server.Execute 方法。
经测试, Response.End 才能正常的终止服务器继续输出内容到浏览器。
另外当Response.End()是用到页面的输出Json格式API接口时候,方法HttpContext.Current.ApplicationInstance.CompleteRequest()不能替代Response.End()。
Response.End()可以禁止继续向页面输出内容(两者的区别在查看页面源代码中发现)。
- 终止线程 Response.End 在Asp.net 里面的正确使用
- 【.NET 】ASP.NET中Response.End()异常
- 【.NET 】ASP.NET中Response.End()异常
- 如何在ASP.NET项目里面正确使用Linq to Sql
- Java中如何正确的终止线程
- asp.net 创建和终止线程(多线程)
- Asp.net中 内置对象Response的Clear、Flush、End、Redirect和方法中的return解析
- ASP.net MVC Response.End(); 之后的代码还会执行
- asp.net 在使用Response.Redirect try{}catch{}块失效
- 在ASP.NET中使用Response.ContentType="类型名"
- asp.net 在使用Response.Redirect try{}catch{}块失效
- response.end 在 jsp下的代替
- asp.net 正确的使用session
- 验证Response.End()方法的使用
- 关于在ASP.NET控件Response弹出窗口的问题
- 在Sharepoint里面使用ASP.NET AJAX Control Toolkit
- Response.End正在中止线程
- response.end() 正在中止线程
- STL--string类的实现
- sql查询distinct 查全表* 不能加括号
- 申请IDP(Iphonedevelop Program)图文教程
- PHP读取文件问题
- adb shell可以识别手机,但eclipse不能识别
- 终止线程 Response.End 在Asp.net 里面的正确使用
- Android.mk简介 .
- Java--collection--List,Set,Map
- 【phpcms-v9】phpcms-v9数据源调用的控制器文件分析phpcms/modules/dbsource/call.php
- 历史上留下浓重一笔的黑客们
- EGLHelper
- This FTP server is anonymous only 解决方案
- Java基本类型与byte数组之间相互转换
- Android Drawable Resource学习(六)、LevelListDrawable