【发布时间】:2022-02-22 10:17:14
【问题描述】:
我在 Linux VM 中的开源 Caprover Paas 中托管了一个 ASP.NET Core Docker Web 应用程序,它运行良好。使用 Caprover 界面,我能够配置站点的 LetsEncrypt SSL 证书,并且浏览器显示一个挂锁并说连接是安全的。问题是 ASP.NET 没有检测到应用程序在 Https 模式下运行,并且Request.IsHttps 始终为假。这是我的测试。
index.cshtml
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
@if (Request.IsHttps)
{
<div class="alert alert-success"><strong>HTTPS:</strong> You are using a secure connection</div>
}
else
{
<div class="alert alert-warning"><strong>HTTP:</strong> Your connection is NOT secure</div>
}
Caprover 使用 Docker 容器和 Nginx 代理服务器,所以我怀疑这是问题,因为Request.IsHttps 在我的 Windows 笔记本电脑上运行应用程序时返回 true。
这是program.cs,只是一个典型的Visual Studio模板。
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
问题是如何配置应用程序以检测它是否在 Https 中运行?
【问题讨论】:
标签: asp.net-core nginx caprover