設定 Web 伺服器的 HTTP 錯誤處理。
Syntax
class HttpErrorsSection : ConfigurationSectionWithCollection
方法
下表列出 類別所 HttpErrorsSection 公開的方法。
| 名稱 | 描述 |
|---|---|
| 加入 | (繼承自 ConfigurationSectionWithCollection.) |
| 清除 | (繼承自 ConfigurationSectionWithCollection。) |
| Get | (繼承自 ConfigurationSectionWithCollection。) |
| GetAllowDefinition | (繼承自 ConfigurationSection.) |
| GetAllowLocation | (繼承自 ConfigurationSection。) |
| 移除 | (繼承自 ConfigurationSectionWithCollection。) |
| RevertToParent | (繼承自 ConfigurationSection。) |
| SetAllowDefinition | (繼承自 ConfigurationSection。) |
| SetAllowLocation | (繼承自 ConfigurationSection。) |
屬性
下表列出 類別所 HttpErrorsSection 公開的屬性。
| 名稱 | 描述 |
|---|---|
DefaultPath |
選擇性 string 值,其中包含 HTTP 錯誤檔或 URL 的預設路徑。 當 nonempty 時,這個值會由 Path 新建立 的 HttpErrorElement 對象的 屬性繼承。 |
DefaultResponseMode |
選擇性 sint32 值,可設定 HTTP 錯誤的預設回應。 當無空時,這個值會由 ResponseMode 新建立 HttpErrorElement 對象的 屬性繼承。 可能的值稍後會列在一節中。 |
DetailedMoreInformationLink |
選擇性的讀取/寫入 string 值,指定頁面底部所顯示之連結的 URL,以及引發之錯誤的詳細資訊頁面。 substatus、status、 hresult和 messageid 錯誤會當做查詢字串的一部分傳送。 您可以使用這個屬性,將終端使用者指向自訂位置以取得錯誤資訊。 預設值為 https://go.microsoft.com/fwlink/?LinkID=62293。 |
ErrorMode |
讀取/寫入 sint32 列舉,指定詳細錯誤功能是否已啟用、停用或只顯示給本機用戶端。 可能的值稍後會列在一節中。 |
ExistingResponse |
讀取/寫入 sint32 列舉,指定 IIS 如何處理現有的自定義錯誤。 可能的值稍後會列在一節中。 |
HttpErrors |
設定特定 HTTP 錯誤的處理值陣列 HttpErrorElement 。 |
Location |
(繼承自 ConfigurationSection.) 索引鍵屬性。 |
Path |
(繼承自 ConfigurationSection.) 索引鍵屬性。 |
SectionInformation |
(繼承自 ConfigurationSection。) |
子類別
這個類別不包含子類別。
備註
這個類別會公開組態檔區 <httpErrors> 段中的設定。
類別所代表的 HttpErrorsSection 自定義錯誤與 IIS 7 相關,且位於 System.WebServer.Configuration 命名空間中。 每個錯誤都是由 HttpErrorElement 類別的實例來表示。
CustomErrorsSection 類別所代表的自定義錯誤專屬於 ASP.NET,而且位於 System.Web 命名空間中。 這些錯誤的每一個都以 CustomError 類別的實例表示。
下表列出 屬性的可能值 DefaultResponseMode 。 預設值為 0 (File) 。
| 值 | 關鍵字 | 描述 |
|---|---|---|
| 0 | File |
Web 伺服器會從 類別的 HttpErrorElement 屬性中指定的Path靜態檔案傳回網頁。 注意: 自定義錯誤是特定語言,通常會以客戶端的語言傳回自定義錯誤。 這需要安裝客戶端的語言套件。 檔案路徑的建構方式如下: PrefixLanguageFilePath\ClientLanguageID\ErrorCodeFile 例如,如果 PrefixLanguageFilePath 是 “d:\inetpub\custerr”,則用戶端瀏覽器會在標頭中 Accept-Language 傳送 “en-us”,而錯誤碼為 404,安裝 en-US 語言套件時產生的路徑會 d:\inetpub\custerr\en-us\404.htm。 如果 ja-JP 是系統語言,且未安裝 en-US 語言套件,則產生的路徑會 d:\inetpub\custerr\ja-jp\404.htm。 |
| 1 | ExecuteURL |
Web 伺服器會傳回 類別的 HttpErrorElement 屬性中指定的Path內部 ASP 頁面。 URL 應位於相同應用程式集區的範圍內。 注意:在 IIS 7 中,重新導向會建立具有下列格式的 URL, (括弧中的專案是選擇性) : /<CustomErrorPage>[?<QueryString>]&resourcePath=<OriginalURL>[?<OriginalQueryString>]&statusCode=<StatusCode> |
| 2 | Redirect |
Web 伺服器會提供HTTP 302 Found回應,並在回應的 欄位中,包含類別的屬性HttpErrorElementLocation中指定的 Path URL。 如果回應是 GET 方法,而不是 HEAD 方法,它也應該包含具有新URL簡短超連結的實體。 注意:在 IIS 7 中,重新導向會建立具有下列格式的 URL, (括弧中的專案是選擇性) : /<CustomErrorPage>[?<QueryString>]&resourcePath=<OriginalURL>[?<OriginalQueryString>]&statusCode=<StatusCode> |
下表列出 屬性的可能值 ErrorMode 。 預設值為 0 (DetailedLocalOnly) 。
| 值 | 關鍵字 | 描述 |
|---|---|---|
| 0 | DetailedLocalOnly |
只有在要求來自本機計算機時,才會產生詳細的錯誤回應。 如果要求來自外部位址,伺服器會產生自定義錯誤回應。 注意: 屬性的值 ExistingResponse 會決定是否產生詳細或自定義錯誤。 |
| 1 | Custom |
模組或伺服器所產生的錯誤會由您指定的自定義頁面取代。 此模式有助於為終端使用者提供更方便的錯誤訊息。 注意: 此設定會關閉詳細的錯誤,即使是針對本機要求。 |
| 2 | Detailed |
顯示應用程式錯誤的詳細資訊頁面,而且不會顯示自定義錯誤。 此模式適用於測試和偵錯網站和應用程式。 注意: 設定為 ErrorModeDetailed的安全性風險是 ,因為即使是遠端用戶端也會收到可能導致垃圾資訊洩漏的詳細錯誤資訊。 |
下表列出 屬性的可能值 ExistingResponse 。 預設值為 0 (Auto) 。
| 值 | 關鍵字 | 描述 |
|---|---|---|
| 0 | Auto |
回應取決於下列一組已排序條件的第一個成功比對: 1.如果使用 旗標呼叫 fTrySkipCustomErrorsIHttpResponse::SetStatus 方法,則會傳遞現有的回應,而且不會顯示詳細的或自定義錯誤。2.如果 ErrorMode 屬性設定 Custom為 ,則會取代回應。3.如果 ErrorMode 設定 Detailed 為 ,而且有現有的回應,則會傳遞回應。4.如果 ErrorMode 設定為 Detailed ,而且沒有現有的回應,則會以詳細的錯誤取代回應。 |
| 1 | Replace |
不論如何 SetStatus 呼叫,現有的回應一律都會被取代。 |
| 2 | PassThrough |
一律會使用現有的回應。 |
範例
下列程式代碼範例會指定、 ErrorMode和 DetailedMoreInformationLink 屬性的新值DefaultPath。 協助程式函式會顯示變更前後的組態區段值。
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Get the HTTP errors section.
Set oSection = oWebAdmin.Get( _
"HttpErrorsSection.Path='" & _
"MACHINE/WEBROOT/APPHOST/',Location=''")
' Display the class name of the section.
WScript.Echo "[ " & oSection.Path_.Class & " ]"
' Display the initial values.
Call DisplayValues("Initial Values", oSection)
' Specify the path of a default error page.
oSection.DefaultPath = _
"D:\inetpub\custerr\en-US\contoso\DefaultErrorPage.htm"
' Specify a detailed more information link.
oSection.DetailedMoreInformationLink = "http://www.contoso.com/MoreInfo.htm"
'Set the ErrorMode property to Custom.
oSection.ErrorMode = 1
' Save the values to configuration.
oSection.Put_
' Refresh the oSection object variable with the new values.
oSection.Refresh_
' Display the changed values.
Call DisplayValues("New Values", oSection)
' ==== DisplayValues helper function. ====
Function DisplayValues(HeadingText, oSection)
' Display a heading.
WScript.Echo
WScript.Echo HeadingText
WScript.Echo String(Len(HeadingText), "-")
' Display the non-embedded section properties.
For Each prop In oSection.Properties_
If Left( _
Prop.Qualifiers_("CIMTYPE"), 6) _
<> "object" then
WScript.Echo prop.Name & ": " & prop.Value
End If
Next
End Function
繼承階層架構
ConfigurationSectionWithCollection
HttpErrorsSection
規格需求
| 類型 | Description |
|---|---|
| 用戶端 | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10 上的 IIS 10.0 |
| 伺服器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016 上的 IIS 10.0 |
| 產品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 |
| MOF 檔案 | WebAdministration.mof |
另請參閱
ConfigurationSection 類別
ConfigurationSectionWithCollection 類別
CustomError 類別
CustomErrorsSection 類別
HttpErrorElement 類別
IHttpResponse::SetStatus 方法