Url Class

https://url.spec.whatwg.org/#url-class

public sealed class Url

Constructors

NameDescription
Url(string, string?)Creates a URL by parsing the given string against the optional base URL; throws a TypeError when it is invalid.

Url(string, string?)

Url.cs

Creates a URL by parsing the given string against the optional base URL; throws a TypeError when it is invalid.

public Url(string url, string? @base = null)

Properties

NameDescription
HashGets or sets the fragment of the URL, prefixed by #, or an empty string when it is empty.
HostGets or sets the host of the URL, followed by the port when it is not the default one.
HostnameGets or sets the host of the URL, without the port.
HrefGets or sets the serialized URL; setting an invalid URL throws a TypeError.
OriginGets the serialized origin of the URL.
PasswordGets or sets the percent-encoded password of the URL.
PathnameGets or sets the serialized path of the URL.
PortGets or sets the port of the URL, or an empty string when it is the default one.
ProtocolGets or sets the scheme of the URL followed by a colon.
SearchGets or sets the query of the URL, prefixed by ?, or an empty string when it is empty.
SearchParamsGets the URLSearchParams object associated with the query of the URL.
UsernameGets or sets the percent-encoded username of the URL.

Hash

Url.cs

Gets or sets the fragment of the URL, prefixed by #, or an empty string when it is empty.

public string Hash { get; set; }

Host

Url.cs

Gets or sets the host of the URL, followed by the port when it is not the default one.

public string Host { get; set; }

Hostname

Url.cs

Gets or sets the host of the URL, without the port.

public string Hostname { get; set; }

Href

Url.cs

Gets or sets the serialized URL; setting an invalid URL throws a TypeError.

public string Href { get; set; }

Origin

Url.cs

Gets the serialized origin of the URL.

public string Origin { get; }

Password

Url.cs

Gets or sets the percent-encoded password of the URL.

public string Password { get; set; }

Pathname

Url.cs

Gets or sets the serialized path of the URL.

public string Pathname { get; set; }

Port

Url.cs

Gets or sets the port of the URL, or an empty string when it is the default one.

public string Port { get; set; }

Protocol

Url.cs

Gets or sets the scheme of the URL followed by a colon.

public string Protocol { get; set; }

SearchParams

Url.cs

Gets the URLSearchParams object associated with the query of the URL.

public UrlSearchParams SearchParams { get; }

Username

Url.cs

Gets or sets the percent-encoded username of the URL.

public string Username { get; set; }

Methods

NameDescription
CanParse(string, string?)Returns whether the given string can be parsed as a URL against the optional base URL.
CreateObjectUrl(Blob)Creates a blob: URL referencing a blob (https://w3c.github.io/FileAPI/#dfn-createObjectURL), until it is revoked or the document of the current global object is destroyed. The URL can be navigated to (e.g. the src of an iframe) by the documents of the browsing context group of the current global object.
CreateObjectUrl(MediaSource)Creates a blob: URL referencing a media source (https://w3c.github.io/media-source/#mediasource-object-url), until it is revoked: a media element whose src attribute (or the one of a source child) is set to the URL attaches the source. The URL of a media source constructed in a dedicated worker cannot be used (the source is attached by its MediaSource.Handle).
Parse(string, string?)Returns the URL obtained by parsing the given string against the optional base URL, or null when it is invalid.
RevokeObjectUrl(string)Revokes a blob: URL created by Url.CreateObjectUrl (https://w3c.github.io/FileAPI/#dfn-revokeObjectURL).
ToJson()Returns the serialized URL, as toJSON() does.
ToString()Returns a string that represents the current object.

CanParse(string, string?)

Url.cs

Returns whether the given string can be parsed as a URL against the optional base URL.

public static bool CanParse(string url, string? @base = null)

CreateObjectUrl overloads

CreateObjectUrl(Blob)

Url.cs

Creates a blob: URL referencing a blob (https://w3c.github.io/FileAPI/#dfn-createObjectURL), until it is revoked or the document of the current global object is destroyed. The URL can be navigated to (e.g. the src of an iframe) by the documents of the browsing context group of the current global object.

public static string CreateObjectUrl(Blob obj)

CreateObjectUrl(MediaSource)

Url.cs

Creates a blob: URL referencing a media source (https://w3c.github.io/media-source/#mediasource-object-url), until it is revoked: a media element whose src attribute (or the one of a source child) is set to the URL attaches the source. The URL of a media source constructed in a dedicated worker cannot be used (the source is attached by its MediaSource.Handle).

public static string CreateObjectUrl(MediaSource obj)

Parse(string, string?)

Url.cs

Returns the URL obtained by parsing the given string against the optional base URL, or null when it is invalid.

public static Url? Parse(string url, string? @base = null)

RevokeObjectUrl(string)

Url.cs

Revokes a blob: URL created by Url.CreateObjectUrl (https://w3c.github.io/FileAPI/#dfn-revokeObjectURL).

public static void RevokeObjectUrl(string url)

ToJson()

Url.cs

Returns the serialized URL, as toJSON() does.

public string ToJson()

ToString()

Url.cs

Returns a string that represents the current object.

public override string ToString()

Returns

string A string that represents the current object.