据我了解,为ASP Dotnet Core 2预览版1/2设置监听端口的正确方法是通过在appsettings.json中以以下格式创建一个Kestrel部分:
From what I understand the correct way of setting listen ports for ASP Dotnet Core 2 preview 1/2 is by creating a Kestrel section in the appsettings.json in the following format:
"Kestrel": { "EndPoints": { //Could also be Endpoints, it's a bit unclear "Http": { "Address": "127.0.0.1", "Port": 9001 //the port you want Kestrel to run on },我试图在Debian机器上设置示例webapp,但是当我启动该应用程序时,它写出该应用程序在端口5000上列出,默认端口。.
I have tried to set up the sample webapp on a Debian machine, but when I start the app, it writes out that the app is listing on port 5000, the default port..
我知道已读取appsettings.json,因为当我将日志记录级别更改为Trace时,我会在启动时获得更多信息,包括没有端点找到并且该应用程序将使用标准的5000端口。
I know that the appsettings.json is read, because when I change the logging level to Trace, I get more info upon startup, including that no Endpoints are found and the app will use the standard 5000 port.
我尝试在Github上搜索aspnet源代码,并且可以找到读取Kestrel部分的区域。来自配置( github/aspb/a1b4a4b1e7b4a1b4e1b3c3b4e1b3c IdentityOIDCWebApplicationSample / MetaPackage / KestrelServerOptionsSetup.cs ),但是正如您所看到的,它看起来像是一个示例项目。
I have tried to search the aspnet source code on Github, and I can find a area where the Kestrel section is read from configuration (github/aspnet/Identity/blob/e38759b8a2de1b7a4a1c19462e40214b43c1cf3b/samples/IdentityOIDCWebApplicationSample/MetaPackage/KestrelServerOptionsSetup.cs), but as you can see it looks like a sample project.
我丢失了什么,这不是在ASP Dotnet核心2中配置Kestrel的标准方法?
What am I missing, isn't this the standard way to configure Kestrel in ASP Dotnet core 2?
推荐答案通过appsettings.json对Kestrel配置的支持在2.0中已删除。
Support for Kestrel configuration via appsettings.json has been dropped in 2.0.
请参见此问题注释:
kestrel配置文件的支持从2.0.0减少。配置值需要在您的初始化代码中手动读取。
kestrel config file support was cut from 2.0.0. Config values need to be read manually in your initialization code.
要解决此问题,您可以在program.cs中执行类似的操作:
To get around this, you can do something like this in program.cs:
public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup < Startup > () .UseKestrel((hostingContext, options) => { if (hostingContext.HostingEnvironment.IsDevelopment) { options.Listen(IPAddress.Loopback, 9001); options.Listen(IPAddress.Loopback, 9002, listenOptions => { listenOptions.UseHttps("certificate.pfx", "password"); }); } }) .Build();更多推荐
使用appsettings.json配置Kestrel监听端口Dotnet Core 2预览2
发布评论