Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hosting.json available options

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 wondering if I can add the https certificate path/password on it.

My hosting.json:

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

Where I'm using 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();
}
like image 298
Tiago Avatar asked Mar 19 '17 20:03

Tiago


People also ask

What is host JSON used for?

The host. json file is a configuration file containing the values that affect all the functions of a function app. This file is created as soon as we add an Azure Function project. This file will have at least one field to begin with, indicating the runtime version of Azure Functions.

What is the use of host JSON in Azure function?

The host. json metadata file contains configuration options that affect all functions in a function app instance. This article lists the settings that are available starting with version 2. x of the Azure Functions runtime.


1 Answers

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<Startup>()
         .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.
like image 113
Shaun Luttin Avatar answered Sep 22 '22 23:09

Shaun Luttin