28

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?

nullPainter
  • 2,676
  • 3
  • 22
  • 42

6 Answers6

30

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"
      }
    }
  }
}
datoml
  • 5,554
  • 4
  • 21
  • 28
Mojtaba
  • 1,470
  • 4
  • 18
  • 25
22

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();
Thomas Hetzer
  • 1,537
  • 13
  • 24
21

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.
  • Legacy ASPNETCORE_SERVER.URLS environment variable.
  • Properties/launchSettings.json.
poke
  • 369,085
  • 72
  • 557
  • 602
  • 2
    Perfect; that was the intent of my question as I didn't knowingly define/remember defining the default binding URL. The severity makes far more sense in that context. I understand your point about the log entry, however since we are logging to a database and non-developers occasionally analyse these logs, I'm keen to minimise logging any extraneous red herrings (not that it now appears, this is). – nullPainter Aug 08 '18 at 07:49
  • Of course; a default URL is defined when you create an ASP.NET Core project in Visual Studio. Feel slightly silly now. – nullPainter Aug 08 '18 at 07:50
  • I'm getting the same warning, where can I find the other environment variables that can cause this? – Ariel Moraes Aug 29 '18 at 19:57
  • Same here @nullPainter. Can you tell us where it is defined? – Mario Tacke Oct 30 '18 at 19:27
  • 1
    @MarioTacke - in my case, it was a silly mistake. From memory, in the VS debug preferences, I had just explicitly set the startup URL to use a different port. – nullPainter Oct 30 '18 at 23:06
  • 4
    I have removed the default URL from launchSettings.json and there are no environment variables defined by me. Yet I still get this warning. Is the list in the answer a complete list? – Sander Jan 20 '21 at 07:54
  • @Sander Can you try running your app using `dotnet run --no-launch-profile` to explicitly disable the `launchSettings.json`? I’m not sure but I could imagine that the launch profile gives the default even if you don’t have an URL in it. – poke Jan 20 '21 at 10:44
11

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.

ccoutinho
  • 3,308
  • 5
  • 39
  • 47
0

None of the the previous answers worked for me. I defined my urls in builder.WebHost.UseKestrel(async options => )

I removed the following from appsettings.json and then the warning was gone.

"AllowedHosts": "*"
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
user3385105
  • 71
  • 2
  • 9
0

If can help someone, I was looking for something for my webapi in .NET 6 What solved for me was using the code below in launch.json

"env": {
  "ASPNETCORE_URLS": "http://localhost:5050"
}