简答
我想知道是否可以在其上添加 https 证书路径/密码。
开箱即用后,您无法使用hosting.json 来设置您的HTTPs 证书和凭证。不过,您可以编写自定义代码来支持该场景。有一个关于此问题的 GitHub 问题 https://github.com/aspnet/Home/issues/1486以及 Tratcher 的示例项目。
我在哪里可以找到关于 Hosting.json 文件中提供的...选项...的文档?
Hosting.json 文件通常将其选项传递给WebHostBuilder.UseConfiguration
method.
-
ASP.NET Core 托管文档 https://learn.microsoft.com/en-us/aspnet/core/fundamentals/hosting#configuring-a-host包括所有已识别选项的描述。
-
GitHub.com/aspnet/hosting https://github.com/aspnet/Hosting包含带有可识别键的静态类。
这是那个静态类:
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
例如,以下 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.
Remarks
- Hosting.json 文件可以具有任何名称。例如,如果愿意,我们可以将其称为 broccoli.json。
- Use
urls
代替server.urls
。后者被列为DeprecatedServerUrlsKey
in the GitHub.com/aspnet/hosting https://github.com/aspnet/Hosting存储库。