gpt4 book ai didi

json - Hosting.json 可用选项

转载 作者:行者123 更新时间:2023-12-02 17:33:46 31 4
gpt4 key购买 nike

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

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

最佳答案

简短回答

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

开箱即用后,您无法使用hosting.json 来设置您的HTTPs 证书和凭证。不过,您可以编写自定义代码来支持该场景。有一个GitHub issue about that以及 Tratcher 的示例项目。

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

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

示例

例如,以下 Hosting.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.

备注

  • hosting.json 文件可以具有任意名称。例如,如果愿意,我们可以将其称为 broccoli.json。
  • 使用urls而不是server.urls。后者在 GitHub.com/aspnet/hosting 中列为 DeprecatedServerUrlsKey存储库。

关于json - Hosting.json 可用选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42892173/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com