HttpListenerResponse.Redirect(String) Метод

Определение

Настраивает ответ для перенаправления клиента на указанный URL-адрес.

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

Параметры

url
String

URL-адрес, который должен использоваться клиентом для обнаружения запрашиваемого ресурса.

Примеры

В следующем примере кода демонстрируется вызов этого метода.

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

Комментарии

Метод Redirect используется для перенаправления клиента в новое расположение ресурса. Этот метод задает для заголовка Location ответа значение url, для StatusCode свойства — значение Redirect, а для StatusDescription свойства — значение "Найдено".

Применяется к

См. также раздел