ASP.NET 發生例外或邏輯錯誤時,處理錯誤提示頁面的三種主要方式:
try { /* 邏輯 */ }
catch (OverflowException)
{
Response.Redirect("ErrorPage.aspx", true);
}
或邏輯驗證失敗:
if (!TTSecurity.IsInRole(TTUser.UserRoleAdministrator))
Response.Redirect("AccessDenied.aspx?Index=-1", true);
<customErrors mode="On" defaultRedirect="ErrorPage.aspx" />
自動攔截未處理例外導向預設錯誤頁,可再細分 HTTP 狀態碼對應不同頁面。
在 Global.asax 的 Application_Error 記錄日誌並 Server.Transfer 至錯誤頁,保留原始例外物件與 URL。