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 标头设置为 urlStatusCode 将 属性设置为 Redirect,将 StatusDescription 属性设置为 “Found”。

适用于

另请参阅