Export (0) Print
Expand All

Uri.IsBaseOf Method

Determines whether the current Uri instance is a base of the specified Uri instance.

Namespace:  System
Assembly:  System (in System.dll)

public bool IsBaseOf(
	Uri uri
)

Parameters

uri
Type: System.Uri

The specified Uri instance to test.

Return Value

Type: System.Boolean
true if the current Uri instance is a base of uri; otherwise, false.

ExceptionCondition
ArgumentNullException

uri is null.

IsBaseOf is used to compare the current Uri instance to a specified Uri to determine whether this URI is a base for the specified Uri. When comparing two Uri objects to determine a base relationship, the user information (UserInfo) is not evaluated. When comparing two URIs (uri1 and uri2), uri1 is the base of uri2 if, when you ignore everything in uri2 after the last slash (/), the two URIs are identical. Using http://host/path/path/file?query as the base URI, the following table shows whether it is a base for other URIs.

URI

http://host/path/path/file?query is base of

http://host/path/path/file/

yes

http://host/path/path/#fragment

yes

http://host/path/path/MoreDir/"

yes

http://host/path/path/OtherFile?Query

yes

http://host/path/path/

yes

http://host/path/path/file

yes

http://host/path/path

no

http://host/path/path?query

no

http://host/path/path#Fragment

no

http://host/path/path2/

no

http://host/path/path2/MoreDir

no

http://host/path/File

no

This example creates a Uri instance that represents a base Uri instance. It then creates a second Uri instance from a string. It calls IsBaseOf to determine whether the base instance is the base of the second instance. The outcome is written to the console.

// Create a base Uri.
Uri baseUri = new Uri("http://www.contoso.com/");

// Create a new Uri from a string.
Uri uriAddress = new Uri("http://www.contoso.com/index.htm?date=today"); 

// Determine whether BaseUri is a base of UriAddress.   
if (baseUri.IsBaseOf(uriAddress))
    Console.WriteLine("{0} is the base of {1}", baseUri, uriAddress);

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft