Codesmith
Codesmith

Reputation: 111

Kestrel override certificate settings from appsetting.development.json

I have this Kestrel settings in appsetting.json

"Kestrel": {
  "Endpoints": {
    "Http": {
      "Url": "http://0.0.0.0:7514"
    },
    "Https": {
      "Url": "https://0.0.0.0:7513"
      "Certificate": {
        "Path": "myCert.pfx",
        "Password": "somePassword"
      }
    }
  }
},

and have this in appsetting.development.json

"Kestrel": {
  "Endpoints": {
    "Http": {
      "Url": "http://0.0.0.0:7514"
    },
    "Https": {
      "Url": "https://0.0.0.0:7515"
      }
    }
}

When in development mode, it uses the correct port from development appsetting, but still expects the certificate, how do I override that settings so it doesn't need the certificate

This is the setup

var webApplicationOptions = new WebApplicationOptions() { ContentRootPath = AppContext.BaseDirectory, Args = args, ApplicationName = System.Diagnostics.Process.GetCurrentProcess().ProcessName };
var builder = WebApplication.CreateBuilder(webApplicationOptions);
builder.Host.UseWindowsService(); 

Upvotes: 1

Views: 133

Answers (2)

Moon
Moon

Reputation: 156

The correct solution is to move the Kestrel settings you have in appsettings.json to appsettings.Production.json. This way the settings won't merge and you'll use exactly one configuration depending on the environment.

Upvotes: 0

Brando Zhang
Brando Zhang

Reputation: 28267

If you want to use https it must need the certificate, it use the certificate to secure the connection between the client and server. Without using it, we couldn't use the tls connection between client and server.

If you don't want to set the certificate for the https, you could remove the https part just use http for testing.

Upvotes: 0

Related Questions