本文介绍了Hosting.json可用选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到有关 hosting.json 文件上可用选项的文档?现在我正在使用 server.ulrs ,但是我想知道是否可以在其上添加https证书路径/密码。

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.

我的 hosting.json

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

我在使用它的地方:

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();
}


推荐答案

简短答案



Short Answer

开箱即用,您不能使用hosting.json来设置HTTPs证书和凭证。但是,您可以编写自定义代码来支持该方案。关于这个的,其中有一个Tratcher的示例项目。

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.

hosting.json文件通常将其选项传递给 WebHostBuilder.UseConfiguration 方法。

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.

这是静态类:

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



示例



例如,以下hosting.json文件...

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. 



备注




  • hosting.json文件可以具有任何名称。例如,我们可以根据需要将其命名为broccoli.json。

  • 使用 urls 代替 server。网址。后者在存储库。

  • 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.
    • 这篇关于Hosting.json可用选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:01