Code: Select all
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"Database": "database_string"
},
"Kestrel": {
"Endpoints": {
"HttpsInlineCertFile": {
"Url": "https://localhost:5001",
"Certificate": {
"Path": "../key/server.pfx",
"Password": "password"
}
}
}
},
"AllowedHosts": "*"
}
Code: Select all
Program.cs
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
if (builder.Environment.IsProduction())
{
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.ConfigureHttpsDefaults(options =>
{
options.SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls13;
});
});
}
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var connectionString = builder.Configuration.GetConnectionString("Database");
builder.Services.AddDbContext(options =>
{
options.UseNpgsql(connectionString);
});
var app = builder.Build();
app.UseDefaultFiles();
app.UseStaticFiles();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.MapFallbackToFile("/index.html");
app.Run();
[img]https://i.sstatic. net/jYGYxAFd.png[/img]
Ich habe die Einstellungen zu Zertifizierungen wie folgt festgelegt.

Wenn jemand weiß, wie man mit Postman den API-Dienst mit Zertifizierungen für https testet, würde ich gerne von Ihnen hören.