首页 > 解决方案 > Linux 上的 ASP.NET Core MVC 应用程序 - Raspberry Pi 无法正确显示

问题描述

我有一个在树莓派上运行的 ASP .Net MVC WebApp,带有 NGINX 服务器。这是一个空白项目,默认的 MVC 项目。

我将其部署并通过网络访问。但是,它在 Pi 上或通过我的笔记本电脑访问时都无法正确显示。

当我从 VS 中的 Debug 运行它时,它确实显示正确。从 VS 调试运行: SP 从 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?}");
        });
    }
}

Linux中的应用安装文件夹: 在此处输入图像描述

标签: c#linuxasp.net-corenginxraspberry-pi

解决方案


根据评论,NGINX 文件指向了错误的目录。问题是“启用站点”位置的配置,而不是指向 HTML 所在的位置。

更多信息请参阅 NGINX 文档或链接: 教程 ASP.NET CORE - PI

解决了!


推荐阅读