关于ASP.NET 解决Response.Redirect ThreadAbortException异常注意事项
2012-07-12 18:44 by kaleyroy, 21 阅读, 0 评论, 收藏, 编辑
大家知道ASP.NET中Response.Redirect()是用来跳转页面的.关于这个不用过多解释. 当在try catch 块中使用的时候会引发ThreadAbortException异常,这个网上很多都说了解决方案,下面我引用MS官方建议的解决方案.
For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event. For Response.Redirect, use an overload, Response.Redirect(String url, bool endResponse) that passes false for the endResponse parameter to suppress the internal call to Response.End.
For example:
Response.Redirect ("nextpage.aspx", false);
If you use this workaround, the code that follows Response.Redirect is executed.
For Server.Transfer, use the Server.Execute method instead.大家注意到红底字部分,人家说明了如果设置false的话:
Response.Redirect ("nextpage.aspx", false);
后面的代码还会继续执行.所以我们应该注意到这一点!
所以我们:
1.当跳转的时候希望完全截断后面的代码,建议Response.Redirect 放到try catch外面使用,或者使用别的更好的方式!
2.当使用Response.Redirect设置为false的时候,记得你后面的代码还是会执行的,别让它影响到你业务处理,谨慎使用
uc浏览器网页版入口官网-手机/电脑uc浏览器网页版入口地址
little fox官方网站入口地址-little fox网页版中国官网入口地址
樱花动漫网官网在线观看入口-樱花动漫网最新网页版入口地址2026
剑桥少儿英语官网入口网址-剑桥少儿英语网页版入口地址
手机百度网盘登录入口地址-百度网盘手机网页版登录入口地址
192.168.1.1无线路由怎么访问?192.168.1.1无线路由器设置登录入口地址