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”。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈