HttpResponse.StatusCode Egenskap

Definition

Hämtar eller anger HTTP-statuskoden för utdata som returneras till klienten.

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

Egenskapsvärde

Ett heltal som representerar statusen för HTTP-utdata som returneras till klienten. Standardvärdet är 200 (OK). En lista över giltiga statuskoder finns i HTTP-statuskoder.

Undantag

StatusCode anges när HTTP-huvudena har skickats.

Exempel

I följande exempel kontrolleras statuskoden för utdataströmmen. Om statuskoden inte är lika med 200 körs ytterligare kod.

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

Gäller för

Se även