背景信息:
dotnet publish -r linux-x64
发布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 /的局部布局>:
背景信息:带RazorPages的ASP.NET Core v3.1在本地运行良好(本地主机上为Win10和Kestrel),只有在部署到Linux VM(Ubuntu 18)时,wwwroot /中的文件才返回404,Bootstrap可以运行...
已解决。
原来,我在运行dotnet aspSample.dll
时没有注意我所在的目录。结果是,我的“内容根路径”将根据执行该命令时所在的位置而改变。为了解决该问题,我必须确保我在Ubuntu VM上的正确目录中,在我的情况下为/publish/
,然后