首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

程式碼閱讀總結:Fitch and Mather 7.0 - 錯誤頁面處理策略

     編輯:關於ASP.NET

ASP.NET 發生例外或邏輯錯誤時,處理錯誤提示頁面的三種主要方式:

1. Response.Redirect 手動導向

try { /* 邏輯 */ }
catch (OverflowException)
{
    Response.Redirect("ErrorPage.aspx", true);
}

或邏輯驗證失敗:

if (!TTSecurity.IsInRole(TTUser.UserRoleAdministrator))
    Response.Redirect("AccessDenied.aspx?Index=-1", true);

2. Web.config 設定

<customErrors mode="On" defaultRedirect="ErrorPage.aspx" />

自動攔截未處理例外導向預設錯誤頁,可再細分 HTTP 狀態碼對應不同頁面。

3. Application_Error 全域攔截

在 Global.asax 的 Application_Error 記錄日誌並 Server.Transfer 至錯誤頁,保留原始例外物件與 URL。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved