I'm following this documentation but I'm getting stuck: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files
Consider my directory structure:
wwwroot
dist
index.html
In my startup class, I have:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))
});
}
When I start the application I don't see my index.html page, but I do if I navigate to <host>/dist/index.html
How can I configure this so that ASP.NET automatically takes me to that page from <host>
?
Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default.
To serve static files from an ASP.NET Core app, you must configure static files middleware. With static files middleware configured, an ASP.NET Core app will serve all files located in a certain folder (typically /wwwroot).
You'll have create middleware or a URL rewrite to do the work for you. ASP.NET Core isn't the smartest and it isn't going to manually do stuff for you.
You should also be doing WebHostBuillder.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist"))
in your Program.cs
file.
Also, this looks like a duplicate of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With