nul*_*ter 12 kestrel-http-server asp.net-core asp.net-core-2.1
在 ASP.NET Core 2.1 项目中使用 Kestrel 并在 中指定绑定时UseKestrel(),会在警告级别记录一条消息:
Overriding address(es) 'http://localhost:50000/'. Binding to endpoints defined in UseKestrel() instead.
这给我们的日志增加了噪音,报告了一个默认(因此令人困惑)的 URL,并且不应该是一个警告。除了记录器本身过滤消息之外,有没有办法配置网络主机构建器,使其在启动时不记录?
pok*_*oke 15
首先,如果您认为在应用程序启动时您只会收到一次,那么“噪音”并不是真正的噪音。因此,除非您在需要重新启动应用程序的地方做了一些奇怪的事情,否则与所有其他(更嘈杂的)消息相比,您可能几乎不会在日志中看到该行。
话虽如此,它实际上是一个有用的警告,因为它告诉您已在多个位置配置了绑定 URL。因此,正确的操作不是忽略该消息,而是实际删除重复的配置。
在这种情况下,您使用的是显式侦听选项,UseKestrel()以便胜过一切。所以你应该删除其他配置。您应该查看几个位置:
ASPNETCORE_URLS 环境变量。ASPNETCORE_SERVER.URLS环境变量。Properties/launchSettings.json.小智 14
有同样有点烦人的警告并检查了环境变量和配置文件,但无法定位 url 列表的来源。最后,我使用IWebHostBuilder.UseUrls()了一个空的 url 列表来消除警告。
IWebHostBuilder builder = new WebHostBuilder()
.UseUrls()
.UseKestrel()
.ConfigureKestrel(...
Run Code Online (Sandbox Code Playgroud)
这是一个老问题,但可以解决之间的冲突launchSettings.json和appSettings.json与"externalUrlConfiguration": true
appSettings.json 中的Kestrel 配置:
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http1AndHttp2"
},
"Endpoints": {
"HTTPS": {
"Url": "https://localhost:4433"
}
}
Run Code Online (Sandbox Code Playgroud)
这是launchSettings.json 的内容:
{
"profiles": {
"TestApplication": {
"commandName": "Project",
"launchBrowser": true,
"externalUrlConfiguration": true, //add this line
"applicationUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
也可能是launchsettings.json和appsettings.json 中包含的配置之间存在冲突
就我而言,在本地开发时,appsettings.json 中的 Kestrel 条目:
"kestrel": {
"endpoints": {
"http": {
"url": "http://localhost:5000"
},
"https": {
"url": "https://localhost:5001"
}
}
Run Code Online (Sandbox Code Playgroud)
与launchsettings.json 中的配置文件冲突:
"MyProject-Dev": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000;https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Run Code Online (Sandbox Code Playgroud)
我相信正确的位置是在launchsettings.json文件中,因此删除appsettings.json中的kestrel条目解决了我的问题。
| 归档时间: |
|
| 查看次数: |
9773 次 |
| 最近记录: |