Class DomainUtilities
Provides utilities to handle domains.
Inheritance
Namespace: Umbraco.Cms.Core.Routing
Assembly: Umbraco.Core.dll
Syntax
public static class DomainUtilities
Methods
View SourceFindWildcardDomainInPath(Nullable<IEnumerable<Domain>>, String, Nullable<Int32>)
Gets the deepest wildcard Domain, if any, from a group of Domains, in a node path.
Declaration
public static Domain FindWildcardDomainInPath(IEnumerable<Domain>? domains, string path, int? rootNodeId)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<IEnumerable<Domain>> | domains | The domains. |
System.String | path | The node path eg '-1,1234,5678'. |
System.Nullable<System.Int32> | rootNodeId | The current domain root node identifier, or null. |
Returns
Type | Description |
---|---|
Domain | The deepest wildcard Domain in the path, or null. |
Remarks
Looks under rootNodeId but not at rootNodeId.
GetCultureFromDomains(Int32, String, Nullable<Uri>, IUmbracoContext, ISiteDomainMapper)
Gets the culture assigned to a document by domains, in the context of a current Uri.
Declaration
public static string GetCultureFromDomains(int contentId, string contentPath, Uri? current, IUmbracoContext umbracoContext, ISiteDomainMapper siteDomainMapper)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | contentId | The document identifier. |
System.String | contentPath | The document path. |
System.Nullable<Uri> | current | An optional current Uri. |
IUmbracoContext | umbracoContext | An Umbraco context. |
ISiteDomainMapper | siteDomainMapper | The site domain helper. |
Returns
Type | Description |
---|---|
System.String | The culture assigned to the document by domains. |
Remarks
In 1:1 multilingual setup, a document contains several cultures (there is not one document per culture), and domains, withing the context of a current Uri, assign a culture to that document.
ParseUriFromDomainName(String, Uri)
Parses a domain name into a URI.
Declaration
public static Uri ParseUriFromDomainName(string domainName, Uri currentUri)
Parameters
Type | Name | Description |
---|---|---|
System.String | domainName | The domain name to parse |
Uri | currentUri | The currently requested URI. If the domain name is relative, the authority of URI will be used. |
Returns
Type | Description |
---|---|
Uri | The domain name as a URI |
PathRelativeToDomain(Uri, String)
Returns the part of a path relative to the uri of a domain.
Declaration
public static string PathRelativeToDomain(Uri domainUri, string path)
Parameters
Type | Name | Description |
---|---|---|
Uri | domainUri | The normalized uri of the domain. |
System.String | path | The full path of the uri. |
Returns
Type | Description |
---|---|
System.String | The path part relative to the uri of the domain. |
Remarks
Eg the relative part of /foo/bar/nil
to domain example.com/foo
is /bar/nil
.
SelectDomain(Nullable<IEnumerable<Domain>>, Uri, String, String, Nullable<Func<IReadOnlyCollection<DomainAndUri>, Uri, String, String, DomainAndUri>>)
Selects the domain that best matches a specified uri and cultures, from a set of domains.
Declaration
public static DomainAndUri SelectDomain(IEnumerable<Domain>? domains, Uri uri, string culture = null, string defaultCulture = null, Func<IReadOnlyCollection<DomainAndUri>, Uri, string, string, DomainAndUri>? filter = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<IEnumerable<Domain>> | domains | The group of domains. |
Uri | uri | An optional uri. |
System.String | culture | An optional culture. |
System.String | defaultCulture | An optional default culture. |
System.Nullable<Func<IReadOnlyCollection<DomainAndUri>, Uri, System.String, System.String, DomainAndUri>> | filter | An optional function to filter the list of domains, if more than one applies. |
Returns
Type | Description |
---|---|
DomainAndUri | The domain and its normalized uri, that best matches the specified uri and cultures. |
Remarks
TODO: must document and explain this all
If uri
is null, pick the first domain that matches culture
,
else the first that matches defaultCulture
, else the first one (ordered by id), else null.
If uri
is not null, look for domains that would be a base uri of the current uri,
If more than one domain matches, then the filter
function is used to pick
the right one, unless it is null
, in which case the method returns null
.
The filter, if any, will be called only with a non-empty argument, and must return something.