簡體   English   中英

Microsoft AspNetCore 環境變量

[英]Microsoft AspNetCore Environment Variables

我一直在尋找一種方法來訪問“HttpReques.PathBase”的默認值。 由於這是在 applicationhost.config 中配置的,我很快發現,這必須通過托管環境以某種方式提供。 原來有一個“ASPNETCORE_APPL_PATH”的環境變量。

However... I was searching for some class, nuget package, microsoft documentation or anything that provides a list of all those constant IIS environment variable keys, including explanations on what exactly they provide. 不幸的是,該搜索與 musks cybertruck 演示文稿中的防彈玻璃一樣成功,這就是為什么我決定為這些常量創建自己的 class:

(我希望這可以幫助一些人......)

 /// <summary>
/// Provides the keys of environment variables.
/// </summary>
public static class C_Env
{
    /// <summary>
    /// Gets the matching value from environment variable.
    /// </summary>
    /// <returns>Value of environment variable as string.</returns>
    public static string Envalue(this string environmentKey)
    {
        try
        {
            return System.Environment.GetEnvironmentVariable(environmentKey);
        }
        catch (Exception)
        {
            return null;
        }
    }

    /// <summary>
    /// Provides the keys of AspNetCore specific environment variables, including .net 5 and above. <br/>
    /// Unfortunately this is not documented anywhere at the moment... so... crap. <br/>
    /// Call
    /// "<a cref="System.Environment">System.Environment.GetEnvironmentVariables();</a>" 
    /// in Debug to see all environment variables. 
    /// </summary>
    public static class AspNetCore 
    {
        /// <summary>
        /// The environment key for the default path base of the application. <br/>
        /// The set pathbase will be available through 
        /// <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httprequest.pathbase">
        /// HttpRequest.PathBase. 
        /// </a>
        /// <br/>
        /// <a href="https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/">
        /// Check this documentation for further details.
        /// </a>
        /// </summary>
        /// <returns>
        /// The default path base as <a cref="string">String</a>.
        /// </returns>
        public const string DefaultPathBase = "ASPNETCORE_APPL_PATH";

        /// <summary>
        /// The environment key for the IIS Web Socket support. <br/>
        /// <a href="https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support">
        /// Check this documentation for further details.
        /// </a>
        /// </summary>
        /// <returns>
        /// <a cref="bool">Bool</a> indicating whether IIS WebSockets are supported by the current environment or not. 
        /// </returns>
        public const string WebSocketSupport = "ASPNETCORE_IIS_WEBSOCKETS_SUPPORTED";

        /// <summary>
        /// The environment key for the physical path of the IIS application. <br/>
        /// <a href="https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/">
        /// Check this documentation for further details.
        /// </a>
        /// </summary>
        /// <returns>
        /// The physical path as <a cref="string">String</a>.
        /// </returns>
        public const string PhysicalPath = "ASPNETCORE_IIS_PHYSICAL_PATH";

        /// <summary>
        /// The environment key for the IIS HTTP authentication type. <br/>
        /// <a href="https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/authentication/">
        /// Check this documentation for further details.
        /// </a>
        /// </summary>
        /// <returns>
        /// The authentication type as <a cref="string">String</a>.
        /// </returns>
        public const string HttpAuth = "ASPNETCORE_IIS_HTTPAUTH";

        /// <summary>
        /// The environment key for the IIS https port of this application.  
        /// </summary>
        /// <returns>
        /// The https port as <a cref="int">int</a>.
        /// </returns>
        public const string HttpsPort = "ASPNETCORE_HTTPS_PORT";

        /// <summary>
        /// The environment key for the AspNetCore port.  
        /// </summary>
        /// <returns>
        /// The AspNetCore port as <a cref="int">int</a>.
        /// </returns>
        public const string AspNetCorePort = "ASPNETCORE_PORT"; //WTF does this provide? like... a fallback port?

        /// <summary>
        /// The environment key for the content root path of the web application. <br/>
        /// The set pathbase will be available through 
        /// <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.ihostingenvironment.contentrootpath">
        /// IHostingEnvironment.ContentRootPath
        /// </a>
        /// <br/>
        /// <a href="https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/">
        /// Check this documentation for further details.
        /// </a>
        /// </summary>
        /// <returns>
        /// The default path base as <a cref="string">String</a>.
        /// </returns>
        public const string ContentRootPath = "ASPNETCORE_CONTENTROOT";

        /// <summary>
        /// The environment key for the https port of the AspNetCore Module for IIS. <br/>
        /// <a href="https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module">
        /// Check this documentation for further details.
        /// </a>
        /// </summary>
        /// <returns>
        /// The https port of the AspNetCore module as <a cref="int">int</a>.
        /// </returns>
        public const string AncmHttpsPort = "ASPNETCORE_ANCM_HTTPS_PORT";

        /// <summary>
        /// The environment key for the AspNetCore token. 
        /// </summary>
        /// <returns>
        /// The AspNetCore Token as <a cref="Guid">GUID</a>.
        /// </returns>
        public const string Token = "ASPNETCORE_TOKEN"; //WTF does this provide? Bearer Token stuff?

        /// <summary>
        /// The environment key for the AspNetCore environment key. (examples: "Development", "Staging")<br/>
        /// <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments">
        /// Check this documentation for further details.
        /// </a>
        /// </summary>
        /// <returns>
        /// The AspNetCore environment key as <a cref="string">string</a>.
        /// </returns>
        public const string Environment = "ASPNETCORE_ENVIRONMENT";

        /// <summary>
        /// The environment key for the AspNetCore hosting startup assemblies. <br/>
        /// <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/platform-specific-configuration">
        /// Check this documentation for further details.
        /// </a>
        /// </summary>
        /// <returns>
        /// The AspNetCore hosting startup assemblies as <a cref="string">string</a>.
        /// </returns>
        public const string HostingStartupAssemblies = "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES";
    }

}

不幸的是,我仍然無法找到所有這些變量的所有信息......請一些船長幫我完成這個列表/文檔嗎?

所以,在那里你可以找到所有的東西,在左邊你可以看到各種鏈接,只是展開一些東西並看到一些標簽的子元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM