Search Results for

    Show / Hide Table of Contents
    View Source

    Interface IHostingEnvironment

    Namespace: Umbraco.Cms.Core.Hosting
    Assembly: Umbraco.Core.dll
    Syntax
    public interface IHostingEnvironment

    Properties

    View Source

    ApplicationId

    The unique application ID for this Umbraco website.

    Declaration
    [Obsolete("Please use IApplicationDiscriminator.Discriminator instead.")]
    string ApplicationId { get; }
    Property Value
    Type Description
    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 Microsoft.Extensions.Hosting.IHostEnvironment.ContentRootPath unless an alternative implementation of IApplicationDiscriminator has been registered).
    However during ConfigureServices a temporary instance of IHostingEnvironment is constructed which guarantees that this will be the hash of Microsoft.Extensions.Hosting.IHostEnvironment.ContentRootPath, so the value may differ depend on when the property is used.

    If you require this value during ConfigureServices it is probably a code smell.

    View Source

    ApplicationMainUrl

    Gets the main application url.

    Declaration
    Uri ApplicationMainUrl { get; }
    Property Value
    Type Description
    Uri
    View Source

    ApplicationPhysicalPath

    Will return the physical path to the root of the application

    Declaration
    string ApplicationPhysicalPath { get; }
    Property Value
    Type Description
    string
    View Source

    ApplicationVirtualPath

    The web application's hosted path.

    Declaration
    string ApplicationVirtualPath { get; }
    Property Value
    Type Description
    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 "/".

    View Source

    IsDebugMode

    Declaration
    bool IsDebugMode { get; }
    Property Value
    Type Description
    bool
    View Source

    IsHosted

    Gets a value indicating whether Umbraco is hosted.

    Declaration
    bool IsHosted { get; }
    Property Value
    Type Description
    bool
    View Source

    LocalTempPath

    Declaration
    string LocalTempPath { get; }
    Property Value
    Type Description
    string
    View Source

    SiteName

    Declaration
    string? SiteName { get; }
    Property Value
    Type Description
    string
    View Source

    TemporaryFileUploadPath

    Gets the location of temporary file uploads.

    Declaration
    string TemporaryFileUploadPath { get; }
    Property Value
    Type Description
    string

    Methods

    View Source

    EnsureApplicationMainUrl(Uri?)

    Ensures that the application know its main Url.

    Declaration
    void EnsureApplicationMainUrl(Uri? currentApplicationUrl)
    Parameters
    Type Name Description
    Uri currentApplicationUrl
    View Source

    MapPathContentRoot(string)

    Maps a virtual path to a physical path to the application's root (not always equal to the web root)

    Declaration
    [Obsolete("Please use the MapPathContentRoot extension method on an instance of IHostEnvironment (or IWebHostEnvironment) instead")]
    string MapPathContentRoot(string path)
    Parameters
    Type Name Description
    string path
    Returns
    Type Description
    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.

    View Source

    MapPathWebRoot(string)

    Maps a virtual path to a physical path to the application's web root

    Declaration
    [Obsolete("Please use the MapPathWebRoot extension method on an instance of IWebHostEnvironment instead")]
    string MapPathWebRoot(string path)
    Parameters
    Type Name Description
    string path
    Returns
    Type Description
    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.

    View Source

    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
    string virtualPath

    The virtual path. Must start with either ~/ or / else an exception is thrown.

    Returns
    Type Description
    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.

    Exceptions
    Type Condition
    InvalidOperationException

    If virtualPath does not start with ~/ or /

    • Edit this page
    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX