HttpListenerResponse.Redirect(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將回應設定為重新導向用戶端至指定的 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 屬性設定為 「Found」。。