I got an ASP .Net MVC WebApp running on raspberry Pi, with NGINX Server. It's a blank project, the default MVC project.
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.
It does display correctly when I run it from the Debug in my VS. Running on Debug from VS: Same app running "Dotnet App.dll" from Linux: I was wondering if I am missing something on the Program.cs or Startup.cs, or if I am publishing it wrong.
Publish Options: File / Release / netcore3.1 / Framework-Dependent / Portable (Tried Linux-arm - same)
Program.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?}");
});
}
}
As per the comments, NGINX Files were pointing to the wrong directory. The problem was the configuration of "sites-enabled" location, not pointing to where the HTML lives.
More info see the NGINX Docs or the LINK: Tutorial ASP.NET CORE - PI
Solved!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.