Export (0) Print
Expand All

HttpWebResponse.ResponseUri Property

Gets the URI of the Internet resource that responded to the request.

Namespace:  System.Net
Assemblies:   System (in System.dll)
  System.Net.Requests (in System.Net.Requests.dll)

Public Overrides ReadOnly Property ResponseUri As Uri

Property Value

Type: System.Uri
A Uri that contains the URI of the Internet resource that responded to the request.


The current instance has been disposed.

The ResponseUri property contains the URI of the Internet resource that actually responded to the request. This URI might not be the same as the originally requested URI, if the original server redirected the request.

The ResponseUri property will use the Content-Location header if present.

Applications that need to access the last redirected ResponseUri should use the HttpWebRequest.Address property rather than ResponseUri, since the use of ResponseUri property may open security vulnerabilities.

This example creates a HttpWebRequest and queries for an HttpWebResponse and then checks to see whether the original URI was redirected by the server.

Dim myUri As New Uri(url)
' Create a 'HttpWebRequest' object for the specified url  
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(myUri), HttpWebRequest)
' Send the request and wait for response. 
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
    Console.WriteLine(ControlChars.Cr + "Request succeeded and the requested information is in the response , Description : {0}", myHttpWebResponse.StatusDescription)
End If 
If myUri.Equals(myHttpWebResponse.ResponseUri) Then
    Console.WriteLine(ControlChars.Cr + "The Request Uri was not redirected by the server")
    Console.WriteLine(ControlChars.Cr + "The Request Uri was redirected to :{0}", myHttpWebResponse.ResponseUri)
End If 
' Release resources of response object.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
© 2015 Microsoft