Wie man das API-Backend von asp.net im https-Format bereitstellt und wie man es integriert, um auf das Frontend zu reagiC#

Ein Treffpunkt für C#-Programmierer
Guest
 Wie man das API-Backend von asp.net im https-Format bereitstellt und wie man es integriert, um auf das Frontend zu reagi

Post by Guest »

Ich entwickle die Web-App „react+asp.net“. Ich habe versucht, das API-Backend von asp.net mithilfe des https-Protokolls zu konfigurieren. Ich habe meine appsettings.json-Datei und Program.cs-Datei des Asp.net Core API-Backends angehängt.

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();
Aber wenn ich versuche, mit Postman eine Antwort zu erhalten, ist der Fehler 404 aufgetreten.
[img]https://i.sstatic. net/jYGYxAFd.png[/img]
Ich habe die Einstellungen zu Zertifizierungen wie folgt festgelegt.
Image
Wenn jemand weiß, wie man mit Postman den API-Dienst mit Zertifizierungen für https testet, würde ich gerne von Ihnen hören.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post