hosting.json available options

后端 未结 1 672
迷失自我
迷失自我 2021-02-14 16:32

Where can I find some documentation regarding which options are available on the hosting.json file? Right now I\'m using the server.ulrs but I\'m wonde

1条回答
  •  误落风尘
    2021-02-14 16:43

    Short Answer

    I'm wondering if can I add the https certificate path/password on it.

    Out of the box, you cannot use hosting.json to set up your HTTPs certificate and credentials. You can, though, write custom code to support that scenario. There is a GitHub issue about that with a sample project by the Tratcher.

    Where can I find ... documentation regarding ... options ... available in the hosting.json file?

    The hosting.json file usually passes its options to the WebHostBuilder.UseConfiguration method.

    • ASP.NET Core hosting documentation includes a description of all recognized options.
    • GitHub.com/aspnet/hosting contains a static class with the recognized keys.

    This is that static class:

    public static class WebHostDefaults
    {
        public static readonly string ApplicationKey = "applicationName";
        public static readonly string StartupAssemblyKey = "startupAssembly";
        public static readonly string DetailedErrorsKey = "detailedErrors";
        public static readonly string EnvironmentKey = "environment";
        public static readonly string WebRootKey = "webroot";
        public static readonly string CaptureStartupErrorsKey = "captureStartupErrors";
        public static readonly string ServerUrlsKey = "urls";
        public static readonly string ContentRootKey = "contentRoot";
    }
    

    Example

    For instance, the following hosting.json file...

    {
        "urls": "http://localhost:12345;http://localhost:54321",
        "contentRoot": "C:\\foobar",
        "environment": "QualityAssurance"
    }
    

    ...and the following entry point...

    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    
    public class Program
    {
        public static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                .AddJsonFile("hosting.json", optional: false)
                .Build();
    
            var host = new WebHostBuilder()
             .UseConfiguration(config)
             .UseKestrel()
             .UseStartup()
             .Build();
    
            host.Run();
        }
    }
    

    ...leads to the following output...

    PS C:\temp> dotnet run                          
    Hosting environment: QualityAssurance           
    Content root path: C:\foobar                    
    Now listening on: http://localhost:12345        
    Now listening on: http://localhost:54321        
    Application started. Press Ctrl+C to shut down. 
    

    Remarks

    • The hosting.json file can have any name. For instance, we can call it broccoli.json if we like.
    • Use urls instead of server.urls. The latter is listed as the DeprecatedServerUrlsKey in the GitHub.com/aspnet/hosting repository.

    0 讨论(0)
提交回复
热议问题