Available hosting.json options

Where can I find some documentation, depending on what options are available in the file hosting.json? I am using right now server.ulrs, but I am wondering if I can add the https certificate path / password to it.

My hosting.json:

{
  "server.urls": "http://0.0.0.0:80;https://0.0.0.0:443"
}

Where do I use it:

public static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("hosting.json", optional: true) // <<<<<<<<< LOADING FILE
        .Build();

    var host = new WebHostBuilder()
        .UseKestrel()
        .UseConfiguration(config) // <<<<<<<<<<< USING IT
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}
+4
source share
1 answer

Short answer

I am wondering if I can add the https certificate path / password to it.

.json HTTP- . , , . GitHub Tratcher.

... ... ..., hosting.json?

host.json WebHostBuilder.UseConfiguration.

:

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";
}

, hosts.json...

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

... ...

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<Startup>()
         .Build();

        host.Run();
    }
}

... ...

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. 

+10

Source: https://habr.com/ru/post/1672688/


All Articles