c# - Linux 上的 ASP.NET Core MVC 应用程序 - Raspberry Pi 无法正确显示
问题描述
我有一个在树莓派上运行的 ASP .Net MVC WebApp,带有 NGINX 服务器。这是一个空白项目,默认的 MVC 项目。
我将其部署并通过网络访问。但是,它在 Pi 上或通过我的笔记本电脑访问时都无法正确显示。
当我从 VS 中的 Debug 运行它时,它确实显示正确。从 VS 调试运行: 从 Linux 运行“Dotnet App.dll”的同一应用程序: 我想知道我是否在 Program.cs 或 Startup.cs 上遗漏了某些内容,或者我是否发布错误。
发布选项:File / Release / netcore3.1 / Framework-Dependent / Portable(尝试过 Linux-arm - 相同)
程序.cs:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseUrls("http://localhost:5000");
webBuilder.UseStartup<Startup>();
});
}
启动.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.Configure<ForwardedHeadersOptions>(options =>
{
options.KnownProxies.Add(IPAddress.Parse("192.168.1.1"));
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/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.UseCookiePolicy();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
解决方案
根据评论,NGINX 文件指向了错误的目录。问题是“启用站点”位置的配置,而不是指向 HTML 所在的位置。
更多信息请参阅 NGINX 文档或链接: 教程 ASP.NET CORE - PI
解决了!
推荐阅读
- pytorch - Pytorch 中是否有一种方法可以以可以反向传播的方式计算唯一值的数量?
- amazon-web-services - 自动为所有 AWS 账户创建相同的策略
- android - 无法从 Android PUT 到 DJANGO REST
- node.js - Access-Control-Allow-Headers 在预检响应中不允许请求标头字段内容类型
- python - 我试图通过列表理解找出下面显示的结果:
- c# - 如何替换仅在符号之前的字符串
- python - 如何使用 for 循环查找嵌套列表的平均值?
- c# - 如何检测精灵是否与任何背景精灵重叠?
- ruby-on-rails - 使用 ruby send 方法创建和构建一个新类
- c# - 按二级关联总和排序