try catch中用了 Response.Redirect 引发的线程异常终止
来源:互联网 发布:nginx 模块 编辑:程序博客网 时间:2024/05/17 09:11
如果使用 try 、catch 处理包含Response.Redirect 语句代码,总是能捕捉到异常:线程正在中止,
其实不仅仅Response.Redirect 会,Response.End 和 Server.Transfer 也是一样的情况,本质的原因的原因是Response.End 方法停止页的执行,并将该执行变换到应用程序的事件管线中的 Application_EndRequest 事件, Response.End 后面的代码行将不执行。通常认为Response.End 方法是线程的非正常结束,因此MS就在内部抛出ThreadAbortException 异常,而Response.Redirect 和 Server.Transfer 这两种方法都在内部调用 Response.End。
症状
如果使用 Response.End、Response.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常。您可以使用 try-catch 语句捕获此异常。
原因
<!-- Inject Script Filtered -->
Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件。不执行 Response.End 后面的代码行。
此问题出现在 Response.Redirect 和 Server.Transfer 方法中,因为这两种方法均在内部调用 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 方法。
阅读全文
0 0
- try catch中用了 Response.Redirect 引发的线程异常终止
- try catch 和 response.Redirect 一个引起的异常!
- asp.net 在使用Response.Redirect try{}catch{}块失效
- asp.net 在使用Response.Redirect try{}catch{}块失效
- Response.Redirect发生线程终止,解决后做个总结
- Response.SubStatusCode”引发了“System.PlatformNotSupportedException”类型的异常
- 捕获异常的Try Catch
- 关于Response.redirect和Response.End出现线程中止异常的处理
- 关于Response.redirect和Response.End出现线程中止异常的处理
- 关于Response.redirect和Response.End出现线程中止异常的处理
- 关于Response.redirect和Response.End出现线程中止异常的处理
- 关于Response.redirect和Response.End出现线程中止异常的处理
- 关于Response.redirect和Response.End出现线程中止异常的处理
- 关于Response.redirect和Response.End出现线程中止异常的处理
- 关于Response.redirect和Response.End出现线程中止异常的处理
- try-catch-finally 引发的奇怪问题
- 一个try{}catch位置引发的血案
- iOS 中用@try @catch
- 多表查询
- 最简单的基于FFmpeg的libswscale的示例(YUV转RGB)
- idea的使用
- DRUID- 查询遇到的坑
- vim按键整理
- try catch中用了 Response.Redirect 引发的线程异常终止
- export和module.export使用案例
- NPC问题证明
- 时间间隔计算工具类
- URG/PSH
- 对于HTML CSS JS的理解
- IntelliJ IDEA使用心得
- 【学习笔记】特征工程(1)
- openstack 管理三十九