ASP.NET Core Web API production HTTPS certificate 101 Level question

barrie 20 Reputation points
2023-08-04T10:33:03.4533333+00:00

Hi, I've created a ASP.NET Core Web API service (using dotnet 6) that pulls data out of a public transport api and updates various internal APIs with that data. The system it runs on is public facing.

The production system is a Windows 2022 server and the app will run as a windows service.

I tried to run the app on the system, but got the error:

general exception: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

I'm used to seeing this on a dev machine and can fix it with:

dotnet dev-certs https --trust

As I understand it - this is just a development process and shouldn't be done on a production public facing system.

Q1: Presumably it can be fixed by generating an HTTPS certificate from one of the many online certificate providers? (Q1a how would that be installed? Q1b and would it work for a Windows Service?)

Q2: Would I need to change anything in the boilerplate code generated by Visual Studio? MSDN seems to imply I need to change it with:

builder.Services.Configure<KestrelServerOptions>(options => {
    options.ConfigureHttpsDefaults(options =>
        options.ClientCertificateMode = ClientCertificateMode.RequireCertificate);
});

Many thanks.

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-08-04T16:15:56.85+00:00

    you are confusing client certificates, which are used for client authentication over a ssl connection and ssl server certificates. see:

    https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-7.0

    once you purchase your x509 certificate, you should get a .pfx file and password

    try:

    builder.WebHost.ConfigureKestrel(serverOptions =>
    {
        serverOptions.ConfigureEndpointDefaults(listenOptions =>
        {
            listenOptions.UseHttps(certFileName, password);
        });
    });
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.