【问题标题】:Not listening on configured UseUrls and launchsettings.json port未侦听配置的 UseUrls 和 launchsettings.json 端口
【发布时间】:2021-09-08 21:14:50
【问题描述】:

我突然无法配置监听的端口。现在默认是踢:

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001

我想使用 6677。

程序.cs:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder
                .UseStartup<Startup>()
                .UseUrls("http://localhost:6677/")
                .UseKestrel();
        });

launchsettings.json:

{
  "profiles": {
    "MyApi": {
      "commandName": "Project",
      "launchBrowser": false,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "local"
      },
      "applicationUrl": "https://localhost:6677;http://localhost:6677"
    }
  }
}

我可以确认我正在使用正确的配置文件,因为正在解析“本地”。

我做了什么?

【问题讨论】:

    标签: asp.net-core asp.net-core-webapi asp.net-core-3.1 kestrel-http-server


    【解决方案1】:

    发生这种情况是因为我将 IConfiguration 实现注入到服务中:

    var configuration = new ConfigurationBuilder()
        .AddJsonFile($"config.{environment.EnvironmentName.ToLower()}.json", optional: false)
        .Build();
    
    services.AddSingleton<IConfiguration>(configuration);
    

    配置项与 URL 完全无关,但我想我已经覆盖了一些东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      • 2017-09-23
      • 1970-01-01
      相关资源
      最近更新 更多