Search code examples
c#asp.netangularpathdefault

How do I change the default path of index.html in .net core?


I use .net core with Angular Cli, so the default structure of ngx is:

dist/project_name/index.html
src/index.html

and so on.

I need to change the default path from wwwroot to

wwwroot/dist/project_name/

How do I change the default path of index.html in .net core?


Actually, I'm willing to set two path variables with .net for dev and prod modes and change it for using it with both ngx modes ng serve and ng build. Maybe you can advice me some best practice how can I do it.


Solution

  • In the Configure Method in startup you could provide StaticFileOptions like this:

        app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")),
        RequestPath = "/StaticFiles"
    });
    

    Further reading: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.1