HttpListenerResponse.RedirectLocation 属性

定义

获取或设置此响应中 HTTP Location 标头的值。

public:
 property System::String ^ RedirectLocation { System::String ^ get(); void set(System::String ^ value); };
public string? RedirectLocation { get; set; }
public string RedirectLocation { get; set; }
member this.RedirectLocation : string with get, set
Public Property RedirectLocation As String

属性值

String,包含要在 Location 标头中发送给客户端的绝对 URL。

例外

为设置操作指定的值为空字符串 ("")。

此对象已关闭。

示例

下面的代码示例演示如何设置此属性。

public static void TemporaryRedirect(HttpListenerRequest request, HttpListenerResponse response)
{
    if (request.Url.OriginalString == @"http://www.contoso.com/index.html")
    {
        response.RedirectLocation = @"http://www.contoso.com/indexServer/index.html";
    }
}
Public Shared Sub TemporaryRedirect(ByVal request As HttpListenerRequest, ByVal response As HttpListenerResponse)
    If request.Url.OriginalString = "http://www.contoso.com/index.html" Then
        response.RedirectLocation = "http://www.contoso.com/indexServer/index.html"
    End If
End Sub

注解

标头 Location 指定客户端定向到的 URL,以便查找请求的资源。

注意

设置此属性不会自动设置 属性 StatusCode

适用于

另请参阅