我在哪里可以找到一些文档,了解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();
}
答案 0 :(得分:16)
我想知道是否可以在其上添加https证书路径/密码。
开箱即用,您无法使用hosting.json来设置HTTPs证书和凭据。但是,您可以编写自定义代码来支持该方案。 Tratcher有一个GitHub issue about that示例项目。
我在哪里可以找到...有关...选项的文档...在hosting.json文件中可用?
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.
urls
代替server.urls
。后者在GitHub.com/aspnet/hosting存储库中列为DeprecatedServerUrlsKey
。