Was "Urls" in appsettings.json ignored in ASP.NET Core 6.0?

Yuta Matsumura 21 Reputation points MVP
2021-11-13T15:52:30.847+00:00

In ASP.NET Core 6.0, is it no longer possible to override the Kestrel URL in appsettings.json > "Urls" as it was up to ASP.NET Core 5.0?

CustomUrlApp.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

</Project>

Program.cs

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

appsettings.json

{
  "Urls": "http://*:5000;https://*:5001",
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

dotnet run's result.

$ dotnet run
ビルドしています...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7207
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5220
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\yuta\source\repos\net6\CustomUrlApp\
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,573 questions
0 comments No comments
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,336 Reputation points Microsoft Vendor
    2021-11-15T03:11:18.127+00:00

    Hi @Yuta Matsumura ,

    To set the Kestrel specific endpoint configuration, you could use the following template in the appsettings.json file:

      "Kestrel": {  
        "Endpoints": {  
          "Https": {  
            "Url": "https://localhost:9999"  
          }  
        }  
      },  
    

    The result is like this: it will override the configuration in the launchSettings.json file.

    149169-image.png


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion


1 additional answer

Sort by: Most helpful
  1. Zdenek Šerý 1 Reputation point
    2022-12-25T17:54:20.35+00:00

    "Kestrel": {
    "Endpoints": {
    "Https": {
    "Url": "https://localhost:9999"
    }
    }
    },

    .net 7 - does not work , .net 6 the same project works fine

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.