简体   繁体   English

Linux 上的 ASP.NET Core MVC 应用程序 - Raspberry Pi 显示不正确

[英]ASP.NET Core MVC App on Linux - Raspberry Pi Not displaying correctly

I got an ASP .Net MVC WebApp running on raspberry Pi, with NGINX Server.我有一个在树莓派上运行的 ASP .Net MVC WebApp,带有 NGINX 服务器。 It's a blank project, the default MVC project.这是一个空白项目,默认的 MVC 项目。

I got it deployed and accessible via the network.我已经部署并通过网络访问了它。 However, it does not display correctly either on the Pi or accessing via from my Laptop.但是,它无法在 Pi 上正确显示或从我的笔记本电脑访问。

It does display correctly when I run it from the Debug in my VS.当我从 VS 中的 Debug 运行它时,它确实显示正确。 Running on Debug from VS:从 VS 调试运行: SP Same app running "Dotnet App.dll" from Linux:从 Linux 运行“Dotnet App.dll”的同一应用程序: 在此处输入图片说明 I was wondering if I am missing something on the Program.cs or Startup.cs, or if I am publishing it wrong.我想知道我是否在 Program.cs 或 Startup.cs 上遗漏了什么,或者我是否发布错误。

Publish Options: File / Release / netcore3.1 / Framework-Dependent / Portable (Tried Linux-arm - same)发布选项:File / Release / netcore3.1 / Framework-Dependent / Portable(尝试过 Linux-arm - 相同)

Program.cs:程序.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>();
            });
}

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?}");
        });
    }
}

App Install Folder in the Linux: Linux 中的应用安装文件夹: 在此处输入图片说明

As per the comments, NGINX Files were pointing to the wrong directory.根据评论,NGINX 文件指向错误的目录。 The problem was the configuration of "sites-enabled" location, not pointing to where the HTML lives.问题是“启用站点”位置的配置,而不是指向 HTML 所在的位置。

More info see the NGINX Docs or the LINK: Tutorial ASP.NET CORE - PI更多信息请参阅 NGINX 文档或链接: 教程 ASP.NET CORE - PI

Solved!解决了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM