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、プロパティを StatusCodeRedirect、プロパティを StatusDescription "Found" に設定します。

適用対象

こちらもご覧ください