【发布时间】:2020-05-11 00:15:12
【问题描述】:
背景信息:
- 带有 RazorPages 的 ASP.NET Core v3.1
- 在本地运行良好(本地主机上的 Win10 和 Kestrel)
- 对于 wwwroot/ 中的文件返回 404仅 在部署到 Linux VM (Ubuntu 18) 时,Bootstrap 在本地工作正常,没有 404s
- 使用
dotnet publish -r linux-x64发布 - 已部署的应用程序正在运行 Kestrel 并正在从 NGINX 转发请求。
Startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
/// Included before other middleware (needed due to nginx forwarding)
/// Per: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-3.1
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseCookiePolicy(); // -- Added for AaaS?
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
// Added to allow controllers
endpoints.MapControllers();
// Original Razor Page way
endpoints.MapRazorPages();
});
}
_Layout_.cshtml
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Title</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
</head>
wwwroot/的部分布局:
- css/
- site.css
- js/
- site.js
- lib/
- 引导程序/
- 分布/
- css/
- bootstrap.css
- jquery/
- 引导程序/
【问题讨论】:
标签: twitter-bootstrap asp.net-core razor http-status-code-404 kestrel-http-server