HttpListenerResponse.Redirect(String) Metoda

Definicja

Konfiguruje odpowiedź w celu przekierowania klienta do określonego adresu URL.

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

Parametry

url
String

Adres URL, którego klient powinien użyć do zlokalizowania żądanego zasobu.

Przykłady

W poniższym przykładzie kodu pokazano wywołanie tej metody.

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

Uwagi

Metoda Redirect służy do przekierowywania klienta do nowej lokalizacji zasobu. Ta metoda ustawia nagłówek odpowiedzi Location na url, StatusCode właściwość na Redirect, a StatusDescription właściwość na "Znaleziono".

Dotyczy

Zobacz też