CustomError.StatusCode 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 HTTP 錯誤狀態碼。
public:
property int StatusCode { int get(); void set(int value); };
[System.Configuration.ConfigurationProperty("statusCode", IsKey=true, IsRequired=true)]
[System.Configuration.IntegerValidator(MaxValue=999, MinValue=100)]
public int StatusCode { get; set; }
[<System.Configuration.ConfigurationProperty("statusCode", IsKey=true, IsRequired=true)>]
[<System.Configuration.IntegerValidator(MaxValue=999, MinValue=100)>]
member this.StatusCode : int with get, set
Public Property StatusCode As Integer
屬性值
HTTP 錯誤狀態碼會導致重定向到自訂錯誤頁面。
- 屬性
範例
以下程式碼範例說明如何使用狀態碼。 參考課堂主題中的 CustomError 程式碼範例,學習如何取得該集合。
// Get second error StatusCode.
CustomError currentError1 =
customErrorsCollection[1];
int currentStatusCode =
currentError1.StatusCode;
// Set the second error StatusCode.
currentError1.StatusCode = 404;
' Get second error StatusCode.
Dim currentError1 As CustomError = _
customErrorsCollection(1)
Dim currentStatusCode As Integer = _
currentError1.StatusCode
' Set the second error StatusCode.
currentError1.StatusCode = 404
備註
ASP.NET 基礎架構使用 HTTP 狀態碼,當特定錯誤發生時,將應用程式重新導向錯誤頁面。
Note
只有當自訂錯誤是由 ASP.NET 處理的實體所造成時才會發出;否則,則會發出標準錯誤。