Interface IHostingEnvironment
Namespace: Umbraco.Cms.Core.Hosting
Assembly: Umbraco.Core.dll
Syntax
public interface IHostingEnvironment
Properties
View SourceApplicationId
The unique application ID for this Umbraco website.
Declaration
string ApplicationId { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The returned value will be the same consistent value for an Umbraco website on a specific server and will the same between restarts of that Umbraco website/application on that specific server.
The value of this does not distinguish between unique workers/servers for this Umbraco application.
Usage of this must take into account that the same ApplicationId may be returned for the same
Umbraco website hosted on different servers.
Similarly the usage of this must take into account that a different
ApplicationId may be returned for the same Umbraco website hosted on different servers.
This returns a hash of the value of IApplicationDiscriminator.Discriminator (which is most likely just the
value of
However during ConfigureServices a temporary instance of IHostingEnvironment is constructed which guarantees
that this will be the hash of
If you require this value during ConfigureServices it is probably a code smell.
ApplicationMainUrl
Gets the main application url.
Declaration
Uri ApplicationMainUrl { get; }
Property Value
Type | Description |
---|---|
Uri |
ApplicationPhysicalPath
Will return the physical path to the root of the application
Declaration
string ApplicationPhysicalPath { get; }
Property Value
Type | Description |
---|---|
System.String |
ApplicationVirtualPath
The web application's hosted path
Declaration
string ApplicationVirtualPath { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
In most cases this will return "/" but if the site is hosted in a virtual directory then this will return the virtual directory's path such as "/mysite". This value must begin with a "/" and cannot end with "/".
IsDebugMode
Declaration
bool IsDebugMode { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsHosted
Gets a value indicating whether Umbraco is hosted.
Declaration
bool IsHosted { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
LocalTempPath
Declaration
string LocalTempPath { get; }
Property Value
Type | Description |
---|---|
System.String |
SiteName
Declaration
string SiteName { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
View SourceEnsureApplicationMainUrl(Nullable<Uri>)
Ensures that the application know its main Url.
Declaration
void EnsureApplicationMainUrl(Uri? currentApplicationUrl)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<Uri> | currentApplicationUrl |
MapPathContentRoot(String)
Maps a virtual path to a physical path to the application's root (not always equal to the web root)
Declaration
string MapPathContentRoot(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path |
Returns
Type | Description |
---|---|
System.String |
Remarks
Depending on the runtime 'web root', this result can vary. For example in Net Framework the web root and the content root are the same, however in netcore the web root is /www therefore this will Map to a physical path within www.
MapPathWebRoot(String)
Maps a virtual path to a physical path to the application's web root
Declaration
string MapPathWebRoot(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path |
Returns
Type | Description |
---|---|
System.String |
Remarks
Depending on the runtime 'web root', this result can vary. For example in Net Framework the web root and the content root are the same, however in netcore the web root is /www therefore this will Map to a physical path within www.
ToAbsolute(String)
Converts a virtual path to an absolute URL path based on the application's web root
Declaration
string ToAbsolute(string virtualPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | virtualPath | The virtual path. Must start with either ~/ or / else an exception is thrown. |
Returns
Type | Description |
---|---|
System.String |
Remarks
This maps the virtual path syntax to the web root. For example when hosting in a virtual directory called "site" and the value "~/pages/test" is passed in, it will map to "/site/pages/test" where "/site" is the value of ApplicationVirtualPath.