Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

WebResponse.ResponseUri Property

When overridden in a derived class, gets the URI of the Internet resource that actually responded to the request.

[Visual Basic]
Public Overridable ReadOnly Property ResponseUri As Uri
[C#]
public virtual Uri ResponseUri {get;}
[C++]
public: __property virtual Uri* get_ResponseUri();
[JScript]
public function get ResponseUri() : Uri;

Property Value

An instance of the Uri class that contains the URI of the Internet resource that actually responded to the request.

Exceptions

Exception Type Condition
NotSupportedException Any attempt is made to get or set the property, when the property is not overridden in a descendant class.

Remarks

The ResponseUri property contains the URI of the Internet resource that actually provided the response data. This resource may not be the originally requested URI if the underlying protocol allows redirection of the request.

Note   The WebResponse class is an abstract (MustInherit in Visual Basic) class. The actual behavior of WebResponse instances at run time is determined by the descendant class returned by WebRequest.GetResponse. For more information about default values and exceptions, please see the documentation for the descendant classes, such as HttpWebResponse and FileWebResponse.

Example

[Visual Basic, C#, C++] The following example uses the ResponseUri property to determine if the location from which the WebResponse originated.

[Visual Basic] 

Dim ourUri As New Uri(url)
' Create a 'WebRequest' object with the specified url. 

Dim myWebRequest As WebRequest = WebRequest.Create(url)

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

' "ResponseUri" property is used to get the actual Uri from where the response was attained.
If ourUri.Equals(myWebResponse.ResponseUri) Then
    Console.WriteLine(ControlChars.Cr + "Request Url : {0} was not redirected", url)
Else
    Console.WriteLine(ControlChars.Cr + "Request Url : {0} was redirected to {1}", url, myWebResponse.ResponseUri)
End If 

' Release resources of response object.
myWebResponse.Close()


[C#] 
Uri ourUri = new Uri(url);            

// Create a 'WebRequest' object with the specified url. 
WebRequest myWebRequest = WebRequest.Create(url); 

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Use "ResponseUri" property to get the actual Uri from where the response was attained.
if (ourUri.Equals(myWebResponse.ResponseUri))
    Console.WriteLine("\nRequest Url : {0} was not redirected",url);   
else
    Console.WriteLine("\nRequest Url : {0} was redirected to {1}",url,myWebResponse.ResponseUri);   
// Release resources of response object.
myWebResponse.Close(); 


[C++] 
Uri* ourUri = new Uri(url);

// Create a 'WebRequest' object with the specified url.
WebRequest* myWebRequest = WebRequest::Create(url);

// Send the 'WebRequest' and wait for response.
WebResponse* myWebResponse = myWebRequest->GetResponse();

// Use "ResponseUri" property to get the actual Uri from where the response was attained.
if (ourUri->Equals(myWebResponse->ResponseUri))
   Console::WriteLine(S"\nRequest Url : {0} was not redirected", url);
else
   Console::WriteLine(S"\nRequest Url : {0} was redirected to {1}", url, myWebResponse->ResponseUri);
// Release resources of response object.
myWebResponse->Close();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

WebResponse Class | WebResponse Members | System.Net Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.