日期:2014-05-18 浏览次数:21515 次
bool hasException = false;
try
{
hasException = false;
//Response.Redirect("A.aspx");
}
catch( Exception e1)
{
hasException = true;
//Response.Redirect("B.aspx");
//Response.Write(" <script>alert('aaaaaaaaaaaa') </script");
}
finally
{
if(hasException )
{
Response.Redirect("B.aspx");
}
else
{
Response.Redirect("A.aspx");
}
}
------解决方案--------------------
MSDN已经解析清楚了
“调用 Redirect 等效于在将第二个参数设置为 true 的情况下调用 Redirect。
Redirect 调用 End,它在完成时引发 ThreadAbortException 异常。”
可见Redirect方法在内部是调用 Thread.Abort()来中止线程的从而引发ThreadAbortException 异常。
如果不想立刻中止则,第二个参数设置为false
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Response.Redirect("A.aspx",false);
}
catch( Exception e1)
{
Response.Redirect("B.aspx");
//Response.Write(" <script>alert('aaaaaaaaaaaa') </script");
}
}