I have a Windows Service hosted web app created with this tutorial (Web Application as Windows Service section): https://csharp.christiannagel.com/2022/03/22/windowsservice-2/
So far everything works. I need set HTTPS endpoint for this app, but I always get the same error message after I try start my service (details below).
For next step I need setup HTTPS endpoint for this app in appsettings.json with thumbprint:
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:5010"
},
"Https": {
"Url": "https://*:5011",
"Certificate": {
"Thumbprint": "D24422F5A62359FAD4B18EBE27A5C14735879333",
"Store": "My",
"Location": "LocalMachine",
"AllowInvalid": "false"
}
}
}
}
The certificate is a DigiCert signed production certificate (not developer certificate).
I imported it to LocalMachine\My store with certlm GUI. I read the thumbprint from store and set in appsettings.json.
Every time I try start my service with these settings it will stop after 2-3 seconds and I see the following error in the eventlog:
CoreCLR Version: 6.0.2023.32017
.NET Version: 6.0.20
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date. To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at Microsoft.AspNetCore.Builder.WebApplication.Run(String url)
at Program.$(String[] args)
I try every combination of settings and install it to another store etc. the error is always the same.
Only thing that works, when I set the certificate with PFX file:
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:5010"
},
"Https": {
"Url": "https://*:5011",
"Certificate": {
"Path": "C:\\CERT\\MY.pfx",
"Password": "Pass1234"
}
}
}
}
But I cannot follow this way, I must use thumbprint instead of a hardcoded password.
The permission of the certificate is set for Everyone (for test), but nothing changes.
Can you help me please how can I make this working? Thanks!


