Serve static index.html file by default

I have a very simple angular application project which should do nothing more than static files from wwwroot . Here is my Startup.cs :

 public class Startup { public void ConfigureServices(IServiceCollection services) { } public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseStaticFiles(); } // Entry point for the application. public static void Main(string[] args) => WebApplication.Run<Startup>(args); } 

Whenever I start a project using IIS Express or web, I always need to go to /index.html . How to do this so that I can just visit the root ( / ) and still get index.html ?

+6
source share
2 answers

Just change app.UseStaticFiles(); on app.UseFileServer();

 public class Startup { public void ConfigureServices(IServiceCollection services) { } public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseFileServer(); } // Entry point for the application. public static void Main(string[] args) => WebApplication.Run<Startup>(args); } 
+5
source

You want the default server static files and files:

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ... // Serve the default file, if present. app.UseDefaultFiles(); app.UseStaticFiles(); ... } 

See the documentation for more information.

+5
source

All Articles