Description





Description

The Uri and UriBuilder classes both represent a Uniform Resource Identifier (URI). Instances of the Uri type are immutable: once the underlying URI is specified, neither it nor its components, or constituent parts, can be changed. The UriBuilder type permits modifications to the components of the URI it represents. The Uri property provides the current contents of a UriBuilder as a Uri instance.

[Note: For more information on URI, see IETF RFC 2396.]

Example

using System;





public class UriBuilderSample

{

    public static void Main()

    {

        String scheme = "http";

        String target = "microsoft.com";

        int port = 8080;

        String path = "samples/page 1.aspx";

        String query = "?q=my value";

        UriBuilder u = new UriBuilder(scheme, target, port,

            path, query);

        Console.WriteLine("Properties for UriBuilder('{0}'"

            + ", '{1}', {2}, {3}, {4})",

            scheme, target, port, path, query);

        ShowUriProperties(u);

        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("Press Enter to continue");

        Console.ReadLine();

    }



    private static void ShowUriProperties(UriBuilder u)

    {

        Console.WriteLine("UriBuilder.Fragment = '{0}'", u.Fragment);

        Console.WriteLine("UriBuilder.Host = '{0}'", u.Host);

        Console.WriteLine("UriBuilder.Password = '{0}'", u.Password);

        Console.WriteLine("UriBuilder.Path = '{0}'", u.Path);

        Console.WriteLine("UriBuilder.Port = {0}", u.Port);

        Console.WriteLine("UriBuilder.Query = '{0}'", u.Query);

        Console.WriteLine("UriBuilder.Scheme = '{0}'", u.Scheme);

        Console.WriteLine("UriBuilder.Uri = {0}", u.Uri);

        Console.WriteLine("UriBuilder.UserName = '{0}'", u.UserName);

    }





}


The output is


Properties for UriBuilder('http', 'microsoft.com', 8080, samples/page 1.aspx, ?q

=my value)

UriBuilder.Fragment = ''

UriBuilder.Host = 'microsoft.com'

UriBuilder.Password = ''

UriBuilder.Path = 'samples/page%201.aspx'

UriBuilder.Port = 8080

UriBuilder.Query = '?q=my value'

UriBuilder.Scheme = 'http'

UriBuilder.Uri = http://microsoft.com:8080/samples/page 1.aspx?q=my value

UriBuilder.UserName = ''





Press Enter to continue



     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows