HttpListenerResponse.Redirect(String) Metoda

Definice

Nakonfiguruje odpověď tak, aby přesměrovává klienta na zadanou 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

Adresa URL, kterou by měl klient použít k vyhledání požadovaného prostředku.

Příklady

Následující příklad kódu ukazuje volání této 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

Poznámky

Metoda Redirect se používá k přesměrování klienta do nového umístění prostředku. Tato metoda nastaví hlavičku odpovědi Location na url, StatusCode vlastnost na Redirecta StatusDescription vlastnost na "Found".

Platí pro

Viz také