Share via


HttpListenerResponse.Redirect(String) Metodo

Definizione

Configura la risposta per reindirizzare il client all'URL specificato.

public:
 void Redirect(System::String ^ url);
public void Redirect (string url);
member this.Redirect : string -> unit
Public Sub Redirect (url As String)

Parametri

url
String

URL che il client deve utilizzare per individuare la risorsa richiesta.

Esempio

Nell'esempio di codice seguente viene illustrata la chiamata a questo metodo.

public static void PermanentRedirect(HttpListenerRequest request, HttpListenerResponse response)
{
    if (request.Url.OriginalString == @"http://www.contoso.com/index.html")
    {
        // Sets the location header, status code and status description.
        response.Redirect(@"http://www.contoso.com/indexServer/index.html");
    }
}
Public Shared Sub PermanentRedirect(ByVal request As HttpListenerRequest, ByVal response As HttpListenerResponse)
    If request.Url.OriginalString = "http://www.contoso.com/index.html" Then
        ' Sets the location header, status code and status description.
        response.Redirect("http://www.contoso.com/indexServer/index.html")
    End If
End Sub

Commenti

Il Redirect metodo viene usato per reindirizzare un client alla nuova posizione per una risorsa. Questo metodo imposta l'intestazione della Location risposta su url, la StatusCode proprietà su Redirecte la StatusDescription proprietà su "Found".

Si applica a

Vedi anche