HttpResponse.StatusCode Proprietà

Definizione

Ottiene o imposta il codice di stato HTTP dell'output restituito al client.

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

Valore della proprietà

Intero che rappresenta lo stato dell'output HTTP restituito al client. Il valore predefinito è 200 (OK). Per un elenco dei codici di stato validi, vedere Codici di stato HTTP.

Eccezioni

Il parametro StatusCode viene impostato dopo l'invio delle intestazioni HTTP.

Esempio

Nell'esempio seguente viene controllato il codice di stato del flusso di output. Se il codice di stato non è uguale a 200, viene eseguito codice aggiuntivo.

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

Si applica a

Vedi anche