I have a .net 7 mini web api running as a windows service (no IIS), and it runs with no problem locally. When I deploy to the prod server I get the following error:
I went through the process to create and add a localhost, x.509 certificate on the server:
My question is, how do I attach this cert to the api. What should be my next steps to configure the api, or what code do I need to add. I've only found answers using IIS, and that not an option for this project. Thanks for the help.
Here's my Program.cs snippet:
var webApplicationOptions = new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService()
? AppContext.BaseDirectory
: default
};
var builder = WebApplication.CreateBuilder(webApplicationOptions);
builder.WebHost.ConfigureKestrel((context, serverOptions) =>
{
var kestrelSection = context.Configuration.GetSection("Kestrel");
serverOptions.Configure(kestrelSection);
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors();
builder.Services.AddHostedService<Worker>();
builder.Host
.UseWindowsService()
.UseSerilog((hostContext, logConfiguration) => logConfiguration.ReadFrom.Configuration(hostContext.Configuration))
.ConfigureServices((hostContext, services) =>
{
services.AddWindowsService();
services.AddHostedService<Worker>();
services.AddMediatR(typeof(Program).Assembly);
services.AddPersistenceServices(hostContext.Configuration);
services.Configure<RabbitMqConfiguration>(config => hostContext.Configuration.GetSection(nameof(RabbitMqConfiguration)).Bind(config));
});
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
});
app.UseCors(p => p.WithOrigins("https://localhost:1234").AllowAnyHeader().AllowAnyMethod().AllowCredentials());
app.MapEndDebtorEndpoints();
app.Run();
And here's the appsettings.json kestrel settings.
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:4321"
},
"Https": {
"Url": "https://localhost:1234"
}
}
},