ConfigureKestrel () конфликтует с настройками приложения - PullRequest
0 голосов
/ 25 сентября 2019

У меня есть раздел Kestrel в appsettings.json, и я также вызываю ConfigureKestrel () в Program.cs.Когда я запускаю приложение, возникает ошибка:

11:10:36 [Warning] () Overriding address(es) '"https://localhost:5003"'. Binding to endpoints defined in "UseKestrel()" instead.

11:10:36 [Fatal] () Unable to start Kestrel.
System.IO.IOException: Failed to bind to address https://[::]:5003: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use ---> System.Net.Sockets.SocketException: Address already in use

Вот мой appsettings.json:

    "Kestrel": {
        "Endpoints": {
          "HttpsInlineCertFile": {
            "Url": "https://localhost:5003",
            "Certificate": {
              "Path": "/tmp/localhost.pfx",
              "Password": "password"
            }
          },
          "HttpsDefaultCert": {
            "Url": "https://localhost:5003"
          },
          "Https": {
            "Url": "https://*:5003",
            "Certificate": {
                "Path": "/tmp/localhost.pfx",
                "Password": "password"
            }
          }
        },
        "Certificates": {
          "Default": {
            "Path": "/tmp/localhost.pfx",
            "Password": "password"
          }
        }
    },

Вот мой ConfigureKestrel ():

            .ConfigureKestrel((context, options) =>
            {
                options.Listen(IPAddress.Any, 5003, listenOptions =>
                {
                    listenOptions.UseHttps(o => o.SslProtocols = SslProtocols.Tls12);
                    listenOptions.UseConnectionLogging();
                    listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
                });
            });

ИЛИ:

            .ConfigureKestrel((context, options) =>
            {
                options.Configure(context.Configuration.GetSection("Kestrel"))
                    .Endpoint("Https", listenOptions =>
                    {
                        listenOptions.HttpsOptions.SslProtocols = SslProtocols.Tls12;
                        listenOptions.ListenOptions.UseConnectionLogging();
                        listenOptions.ListenOptions.Protocols = HttpProtocols.Http1AndHttp2;
                    });
            });

Итак, что есть что?Я смущен.Могу ли я сделать все в appsettings.json?

Обновление : я выяснил, как настроить другие параметры в appsettings.json, кроме 2: listenOptions.HttpsOptions.SslProtocols и UseConnectionLogging

...