UriBuilder Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the UriBuilder class.
Overloads
UriBuilder() |
Initializes a new instance of the UriBuilder class. |
UriBuilder(String) |
Initializes a new instance of the UriBuilder class with the specified URI. |
UriBuilder(Uri) |
Initializes a new instance of the UriBuilder class with the specified Uri instance. |
UriBuilder(String, String) |
Initializes a new instance of the UriBuilder class with the specified scheme and host. |
UriBuilder(String, String, Int32) |
Initializes a new instance of the UriBuilder class with the specified scheme, host, and port. |
UriBuilder(String, String, Int32, String) |
Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, and path. |
UriBuilder(String, String, Int32, String, String) |
Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, path, and query string or fragment identifier. |
UriBuilder()
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
Initializes a new instance of the UriBuilder class.
public:
UriBuilder();
public UriBuilder ();
Public Sub New ()
Remarks
The parameterless constructor creates a new instance of the UriBuilder class with its properties initialized as follows.
Property | Initial Value |
---|---|
Fragment | Empty |
Host | "loopback" |
Password | Empty |
Path | "/" |
Port | -1 |
Query | Empty |
Scheme | "http" |
UserName | Empty |
Applies to
UriBuilder(String)
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
Initializes a new instance of the UriBuilder class with the specified URI.
public:
UriBuilder(System::String ^ uri);
public UriBuilder (string uri);
new UriBuilder : string -> UriBuilder
Public Sub New (uri As String)
Parameters
- uri
- String
A URI string.
Exceptions
uri
is null
.
uri
is a zero-length string or contains only spaces.
-or-
The parsing routine detected a scheme in an invalid form.
-or-
The parser detected more than two consecutive slashes in a URI that does not use the "file" scheme.
-or-
uri
is not a valid URI.
Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.
Remarks
This constructor initializes a new instance of the UriBuilder class with the Fragment, Host, Path, Port, Query, Scheme, and Uri properties set as specified in uri
.
If uri
does not specify a scheme, the scheme defaults to "http:".
Applies to
UriBuilder(Uri)
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
Initializes a new instance of the UriBuilder class with the specified Uri instance.
public:
UriBuilder(Uri ^ uri);
public UriBuilder (Uri uri);
new UriBuilder : Uri -> UriBuilder
Public Sub New (uri As Uri)
Parameters
Exceptions
uri
is null
.
Remarks
This constructor initializes a new instance of the UriBuilder class with the Fragment, Host, Path, Port, Query, Scheme, and Uri properties set as specified in uri
.
Applies to
UriBuilder(String, String)
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
Initializes a new instance of the UriBuilder class with the specified scheme and host.
public:
UriBuilder(System::String ^ schemeName, System::String ^ hostName);
public UriBuilder (string schemeName, string hostName);
public UriBuilder (string? schemeName, string? hostName);
new UriBuilder : string * string -> UriBuilder
Public Sub New (schemeName As String, hostName As String)
Parameters
- schemeName
- String
An Internet access protocol.
- hostName
- String
A DNS-style domain name or IP address.
Examples
The following example creates a UriBuilder instance that contains the URI http://www.contoso.com/
.
UriBuilder^ myUri = gcnew UriBuilder( "http", "www.contoso.com" );
UriBuilder myUri = new UriBuilder("http","www.contoso.com");
let myUri = UriBuilder "http","www.contoso.com"
Dim myUri As New UriBuilder("http", "www.contoso.com")
Remarks
The UriBuilder instance is initialized with the Scheme property set to schemeName
and the Host property set to hostName
. Port is initialized to the value -1 to indicate the default port for the scheme should be used, and the Path property is set to the slash character (/).
Applies to
UriBuilder(String, String, Int32)
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
Initializes a new instance of the UriBuilder class with the specified scheme, host, and port.
public:
UriBuilder(System::String ^ scheme, System::String ^ host, int portNumber);
public UriBuilder (string scheme, string host, int portNumber);
public UriBuilder (string? scheme, string? host, int portNumber);
new UriBuilder : string * string * int -> UriBuilder
Public Sub New (scheme As String, host As String, portNumber As Integer)
Parameters
- scheme
- String
An Internet access protocol.
- host
- String
A DNS-style domain name or IP address.
- portNumber
- Int32
An IP port number for the service.
Exceptions
portNumber
is less than -1 or greater than 65,535.
Examples
The following example creates a UriBuilder instance that contains the URI http://www.contoso.com:8080/
.
UriBuilder^ myUri = gcnew UriBuilder( "http", "www.contoso.com",8080 );
UriBuilder myUri = new UriBuilder("http","www.contoso.com",8080);
let myUri = UriBuilder("http","www.contoso.com", 8080)
Dim myUri As New UriBuilder("http", "www.contoso.com", 8080)
Remarks
The UriBuilder instance is initialized with the Scheme property set to schemeName
, the Host property set to hostName
, and the Port property set to portNumber
. The Path property is set to the slash character (/).
If the portNumber
is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host.
Applies to
UriBuilder(String, String, Int32, String)
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, and path.
public:
UriBuilder(System::String ^ scheme, System::String ^ host, int port, System::String ^ pathValue);
public UriBuilder (string scheme, string host, int port, string pathValue);
public UriBuilder (string? scheme, string? host, int port, string? pathValue);
new UriBuilder : string * string * int * string -> UriBuilder
Public Sub New (scheme As String, host As String, port As Integer, pathValue As String)
Parameters
- scheme
- String
An Internet access protocol.
- host
- String
A DNS-style domain name or IP address.
- port
- Int32
An IP port number for the service.
- pathValue
- String
The path to the Internet resource.
Exceptions
port
is less than -1 or greater than 65,535.
Examples
The following example creates a UriBuilder instance that contains the URI http://www.contoso.com:8080/index.htm
.
UriBuilder^ myUri = gcnew UriBuilder( "http","www.contoso.com",8080,"index.htm" );
UriBuilder myUri = new UriBuilder("http","www.contoso.com",8080,"index.htm");
let myUri = UriBuilder("http","www.contoso.com", 8080, "index.htm")
Dim myUri As New UriBuilder("http", "www.contoso.com", 8080, "index.htm")
Remarks
The UriBuilder instance is initialized with the Scheme property set to schemeName
, the Host property set to hostName
, the Port property set to portNumber
, and the Path property set to pathValue
.
If the portNumber
is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host.
Applies to
UriBuilder(String, String, Int32, String, String)
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
- Source:
- UriBuilder.cs
Initializes a new instance of the UriBuilder class with the specified scheme, host, port number, path, and query string or fragment identifier.
public:
UriBuilder(System::String ^ scheme, System::String ^ host, int port, System::String ^ path, System::String ^ extraValue);
public UriBuilder (string scheme, string host, int port, string path, string extraValue);
public UriBuilder (string? scheme, string? host, int port, string? path, string? extraValue);
new UriBuilder : string * string * int * string * string -> UriBuilder
Public Sub New (scheme As String, host As String, port As Integer, path As String, extraValue As String)
Parameters
- scheme
- String
An Internet access protocol.
- host
- String
A DNS-style domain name or IP address.
- port
- Int32
An IP port number for the service.
- path
- String
The path to the Internet resource.
- extraValue
- String
A query string or fragment identifier.
Exceptions
extraValue
is neither null
nor Empty, nor does a valid fragment identifier begin with a number sign (#), nor a valid query string begin with a question mark (?).
port
is less than -1 or greater than 65,535.
Examples
The following example creates a UriBuilder instance that contains the URI http://www.contoso.com:8080/index.htm#top
.
UriBuilder^ myUri = gcnew UriBuilder( "http","www.contoso.com",8080,"index.htm","#top" );
UriBuilder myUri = new UriBuilder("http","www.contoso.com",8080,"index.htm","#top");
let myUri = UriBuilder("http","www.contoso.com", 8080, "index.htm", "#top")
Dim myUri As New UriBuilder("http", "www.contoso.com", 8080, "index.htm", "#top")
Remarks
The UriBuilder instance is initialized with the Scheme property set to schemeName
, the Host property set to hostName
, the Port property set to portNumber
, and the Path property set to pathValue
. If extraValue
begins with a number sign (#), then Fragment is set to extraValue
. If extraValue
begins with a question mark (?), then Query is set to extraValue
.
If the portNumber
is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host.