HttpListenerResponse.Redirect(String) HttpListenerResponse.Redirect(String) HttpListenerResponse.Redirect(String) HttpListenerResponse.Redirect(String) Method

定義

將回應設定為重新導向用戶端至指定的 URL。Configures the response to redirect the client to the specified 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 String String String

用戶端應用來尋找所要求之資源的 URL。The URL that the client should use to locate the requested resource.

範例

下列程式碼範例示範如何呼叫這個方法。The following code example demonstrates calling this method.

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方法用來將用戶端重新導向至新位置的資源。The Redirect method is used to redirect a client to the new location for a resource. 這個方法會設定的回應Location標頭url,則StatusCode屬性設Redirect,和StatusDescription"Found"的屬性。This method sets the response's Location header to url, the StatusCode property to Redirect, and the StatusDescription property to "Found".

適用於

另請參閱