Class UrlBuilder
Extend the UriBuilder class to make http-assumptions about relative Url's. Use like/instead of System.UriBuilder, but it will handle relative Uri's as if they are http-Uri's.
Inheritance
Namespace: EPiServer
Assembly: EPiServer.dll
Version: 12.0.3Syntax
public class UrlBuilder : Object
Examples
The example below shows how to useUrlBuilder to merge query strings.
NameValueCollection myCol = new NameValueCollection();
myCol.Add("SkipCount", "1");
myCol.Add("Year", "2009");
UrlBuilder urlBuilder = new UrlBuilder(CurrentPage.LinkURL);
urlBuilder.MergeQueryCollection(myCol);
string pageLink = (string)urlBuilder;
Constructors
UrlBuilder(Url)
Initializes a new instance of the UrlBuilder class.
Declaration
public UrlBuilder(Url url)
Parameters
Type | Name | Description |
---|---|---|
Url | url | The URL. |
UrlBuilder(UrlBuilder)
Initializes a new instance of the UrlBuilder class.
Declaration
public UrlBuilder(UrlBuilder url)
Parameters
Type | Name | Description |
---|---|---|
UrlBuilder | url | The URL builder. A memberwise copy is made. |
UrlBuilder(String)
Initializes a new instance of the UrlBuilder class.
Declaration
public UrlBuilder(string url)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | The URL. |
UrlBuilder(Uri)
Initializes a new instance of the UrlBuilder class.
Declaration
public UrlBuilder(Uri url)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | url | The URL. |
Properties
Encoding
Gets the encoding used for unescaping and escaping.
Declaration
public Encoding Encoding { get; set; }
Property Value
Type | Description |
---|---|
System.Text.Encoding | The encoding. The default is UTF-8. |
Fragment
Gets the escaped fragment.
Declaration
public string Fragment { get; set; }
Property Value
Type | Description |
---|---|
System.String | A string containing any URI fragment information. |
Remarks
This property will strip any # charactes at the beginning of the string when setting the property since they are added by the underlying System.UriBuilder.
HasAuthorityPart
Gets a value indicating whether this instance has any authority part (scheme, username, password, port, host)
Declaration
public bool HasAuthorityPart { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Host
Gets the host component of this instance.
Declaration
public string Host { get; set; }
Property Value
Type | Description |
---|---|
System.String | A String containing the host name. This is usually the DNS host name or IP address of the server. |
IsEmpty
Gets a value indicating whether this instance is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
IsPathRelative
Gets a value indicating whether the path is relative.
Declaration
public bool IsPathRelative { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Password
Gets or sets the password.
Declaration
public string Password { get; set; }
Property Value
Type | Description |
---|---|
System.String | The password. |
Path
Gets the path. Will return a relative path if the path was relative to start with.
Declaration
public string Path { get; set; }
Property Value
Type | Description |
---|---|
System.String | The path. |
Port
Gets the port number of this URL.
Declaration
public int Port { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | An int value containing the port number for this URL, or -1 for no value set |
Query
Gets any query information included in the specified URL.
Declaration
public string Query { get; set; }
Property Value
Type | Description |
---|---|
System.String | A String containing any query information included in the specified URL. |
Remarks
The Query property contains any query information included in the URI. Query information is separated from the path information by a question mark (?) and continues to the end of the URI. The query information returned includes the leading question mark. The query information is escaped according to RFC 3986.
QueryCollection
Gets or sets a parsed and decoded collection of query string parameters.
Declaration
public NameValueCollection QueryCollection { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Specialized.NameValueCollection | The query collection. |
QueryId
Gets and sets the id in the QueryCollection
Declaration
public string QueryId { get; set; }
Property Value
Type | Description |
---|---|
System.String |
QueryLanguage
Gets and sets the epslanguage in the QueryCollection
Declaration
public string QueryLanguage { get; set; }
Property Value
Type | Description |
---|---|
System.String |
QueryTemplate
Gets and sets the epstemplate in the QueryCollection
Declaration
public string QueryTemplate { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Scheme
Gets the scheme name for this URL.
Declaration
public string Scheme { get; set; }
Property Value
Type | Description |
---|---|
System.String | A String containing the scheme for this URL, converted to lowercase. |
ThisBuilder
Gets or sets this instances' UriBuilder.
Declaration
protected UriBuilder ThisBuilder { get; set; }
Property Value
Type | Description |
---|---|
System.UriBuilder | This instances' builder. |
Uri
Gets or sets the Uri.
Declaration
public Uri Uri { get; set; }
Property Value
Type | Description |
---|---|
System.Uri | The URI. |
UserName
Gets or sets the user name
Declaration
public string UserName { get; set; }
Property Value
Type | Description |
---|---|
System.String | The user name. |
Methods
MergeQueryCollection(NameValueCollection)
Merges the query collection with the passed collection.
Declaration
public void MergeQueryCollection(NameValueCollection masterQueryCollection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.NameValueCollection | masterQueryCollection | The master query collection. |
Remarks
If the parameter already exists in the UrlBuilders QueryCollection it will be overwritten with the parameter from the master query collection.
ToString()
Returns a canonical string representation for the specified Url instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A String instance that contains the unescaped canonical representation of the Uri instance. |
Remarks
Do NOT use this method except for debug and human readable output. To get the properly escaped string, cast to a string with (string).
Operators
Explicit(UrlBuilder to String)
Convert the instance to a properly escaped string
Declaration
public static explicit operator string (UrlBuilder ub)
Parameters
Type | Name | Description |
---|---|---|
UrlBuilder | ub | The UrlBuilder to convert |
Returns
Type | Description |
---|---|
System.String | A converted UrlBuilder as a string |