背景信息:
dotnet publish -r linux-x64
启动文件
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 /的部分布局:
解决。
原来,我在运行时没有注意我所在的目录dotnet aspSample.dll
。结果是,我的“内容根路径”将根据执行该命令时的位置而改变。要解决此问题,我必须确保在Ubuntu VM上的正确目录/publish/
中,然后运行dotnet aspSample.dll
以确保Content root path: /var/www/aspSample/publish
正确设置了
在查看了这篇文章的不可接受的答案后:Asp.Net Core 2.0-2.2 Kestrel不提供静态内容我看到了我的答案,但描述得更好,因此在下面引用了其块。
对我来说,问题在于工作目录。尝试使用dotnet /var/www/project/project.dll启动应用程序时,我并没有注意我所在的目录。这样启动应用程序时,它将自动将当前目录用作工作目录。
当我查看另一个项目的.service文件时,意识到了这一点,该文件指定了WorkingDirectory:
... WorkingDirectory=/var/www/project/ ExecStart=/usr/bin/dotnet /var/www/project/project.dll ...
因此,在运行项目时,请确保您位于正确的目录中,或者确保在.service文件中正确设置了WorkingDirectory。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句