Background Info:
- ASP.NET Core v3.1 w/ RazorPages
- Works fine locally (Win10 & Kestrel on localhost)
- Returns 404 for files in wwwroot/ only on deployment to Linux VM (Ubuntu 18), Bootstrap works fine locally, no 404s
- Publishing with
dotnet publish -r linux-x64 - The deployed app is running Kestrel and being forwarded requests from 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>
partial layout of wwwroot/:
- css/
- site.css
- js/
- site.js
- lib/
- bootstrap/
- dist/
- css/
- bootstrap.css
- jquery/
- bootstrap/