When using Kestrel in an ASP.NET Core 2.1 project and specifying a binding in UseKestrel()
, a message is logged at warning level:
Overriding address(es) 'http://localhost:50000/'. Binding to endpoints defined in UseKestrel() instead.
This adds noise to our logs, reports a default (and therefore confusing) URL, and shouldn't be a warning. Short of filtering the message by the logger itself, is there a way to configure the web host builder so it doesn't log this on startup?
Had the same slightly annoying warning and checked the environment variables and configuration files, but was unable to locate the source of the url list. In the end I used IWebHostBuilder.UseUrls()
with an empty list of urls to get rid of the warning.
IWebHostBuilder builder = new WebHostBuilder()
.UseUrls()
.UseKestrel()
.ConfigureKestrel(...
Edit: For .net6
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseUrls();
First of all, that “noise” is not really that noise if you consider that you only get this once when the application starts. So unless you are doing something weird where you need to restart your app, then you will probably almost never see that line in your logs, compared to all those other (much noisier) messages.
That being said, it is actually a useful warning because it tells you that you have configured the binding URL in multiple locations. So the proper action is not to ignore that message but to actually remove the duplicate configurations.
In this case, you are using explicit listen options with UseKestrel()
so that trumps everything. So you should remove the other configurations. There are a few locations where you should look:
ASPNETCORE_URLS
environment variable.ASPNETCORE_SERVER.URLS
environment variable.Properties/launchSettings.json
.This is an old question but you can resolve that conflict between launchSettings.json and appSettings.json with "externalUrlConfiguration": true
Kestrel configuration in appSettings.json:
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http1AndHttp2"
},
"Endpoints": {
"HTTPS": {
"Url": "https://localhost:4433"
}
}
And this is launchSettings.json content:
{
"profiles": {
"TestApplication": {
"commandName": "Project",
"launchBrowser": true,
"externalUrlConfiguration": true, //add this line
"applicationUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
It can also be a conflict between the configuration contained in launchsettings.json and appsetings.json
In my case, while developing locally, the Kestrel entry in appsetings.json:
"kestrel": {
"endpoints": {
"http": {
"url": "http://localhost:5000"
},
"https": {
"url": "https://localhost:5001"
}
}
was conflicting with a profile in the launchsettings.json:
"MyProject-Dev": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000;https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
I believe the right place for this is in the launchsettings.json file, so removing the kestrel entry in the appsettings.json solved my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With