Response.Redirect 內部呼叫 Response.End(),導致執行緒中止,拋出 ThreadAbortException,必然進入 catch 區塊。
Application_EndRequest,不中止執行緒。Response.Redirect(url); Context.ApplicationInstance.CompleteRequest();endResponse=false 避免內部呼叫 Response.End(),後續程式碼可繼續執行。Response.Redirect("/mymaimai.aspx", false);Server.Transfer(),不中止當前請求。try
{
Response.Redirect("/mymaimai.aspx", false);
}
catch
{
// 真正的例外處理
}
微軟設計使然,採用方案二最簡潔且語意明確。