我正在尝试在 Azure 容器应用程序上设置 Blazor 服务器。 我已经在 HTTP 端口 80 上设置了入口的容器,添加了带有托管证书的自定义域名。
除了 OpenID 连接之外,一切正常。 重定向 URI 以 http:// 开头,而不是 https://
我很确定这是因为图像使用端口 80,但是当我将其设置为 443 时,我收到了证书丢失错误。
如何将证书传递给 docker 实例?或者我应该做点别的吗?
正如@ahmelsayed 提到的,我在我的program.cs 文件中使用了以下配置:
var builder = WebApplication.CreateBuilder(args);
//Service registration (cut for simplicity)
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
else
{
app.UseDeveloperExceptionPage();
}
app.UseForwardedHeaders();
//some other call not specific to the solution
app.Run();
在
Blazor Web App
中运行的 .NET 9
上看到与 Azure Web App for Containers in Linux
相同的问题。
为了让它开始工作,
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
// Other service registrations
WebApplication app = builder.Build();
// Note: Forwarded Headers Middleware should run before other middleware.
// This ordering ensures that the middleware relying on forwarded headers information can consume the header values for processing.
// Forwarded Headers Middleware can run after diagnostics and error handling, but it MUST BE RUN before calling UseHsts:
app.UseForwardedHeaders();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
app.UseHttpsRedirection();
// Other middleware
{
"name": "ASPNETCORE_FORWARDEDHEADERS_ENABLED",
"value": "true",
"slotSetting": false
}