本文介绍了为什么Response.Redirect总是在内部抛出一个异常,由框架自动解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在try块中编写Response.Redirect,我刚遇到 System.Threading.ThreadAbortException 异常。请参阅下面我编写的代码。

I just encountered "System.Threading.ThreadAbortException" exception if I write Response.Redirect in a try block. See below the code I have written.

protected void btnVisitSecondPage_Click(object sender, EventArgs e)

Response.Redirect("frmSecondPage.aspx");
}
catch (Exception ex) { } 
} 



上面的代码工作正常,但如果我调试它,我可以看到 Response.Redirect 抛出 System.Threading.ThreadAbortException 异常并由framewrok自动解决。



最奇怪的部分是,如果我删除了try块,那么它也可以正常运行而不会抛出异常。



见下面的代码


Above code is working fine but if I debug it, I can see Response.Redirect throws "System.Threading.ThreadAbortException" exception and gets resolved by the framewrok autonmatically.

Most strange part is that if I remove the try block then it also works fine without throwing an exception .

See below the code

protected void btnVisitSecondPage_Click(object sender, EventArgs e)Response.Redirect("frmSecondPage.aspx");



任何人都可以给我解释一下吗?


Can any one please give me the explanation ?

推荐答案

我希望它能解释您的问题。 

I hope it explains your problem. 


Page1有一个带有response.redirect到第2页的按钮

Page1 had a button with a response.redirect to page2

Page2有一个带有response.redirect wi的按钮将try1块稀释到page1。

Page2 had a button with a response.redirect within a try block to page1.

它没有任何问题。



这篇关于为什么Response.Redirect总是在内部抛出一个异常,由框架自动解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:33