HttpResponse.StatusCode 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定回傳給用戶端的輸出的 HTTP 狀態碼。
public:
property int StatusCode { int get(); void set(int value); };
public int StatusCode { get; set; }
member this.StatusCode : int with get, set
Public Property StatusCode As Integer
屬性值
一個整數代表回傳給用戶端的 HTTP 輸出狀態。 預設值是 200(OK)。 有關有效狀態碼的清單,請參見 HTTP 狀態碼。
例外狀況
StatusCode 是在 HTTP 標頭傳送後設定的。
範例
以下範例檢查輸出串流的狀態碼。 若狀態碼不等於 200,則執行額外程式碼。
protected void Page_Load(object sender, EventArgs e)
{
// Show success or failure of page load.
if (Response.StatusCode != 200)
{
Response.Write("There was a problem accessing the web resource" +
"<br />" + Response.StatusDescription);
}
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Show success or failure of page load.
If Response.StatusCode <> 200 Then
Response.Write("There was a problem accessing the web resource." & _
"<br />" & Response.StatusDescription)
End If
End Sub