Home > other >  How to set a static html page as homepage of an ASP.NET Core Web API?
How to set a static html page as homepage of an ASP.NET Core Web API?

Time:07-12

I am learning ASP.NET Core Web API. I followed the enter image description here

Swagger and others all work well! but I cannot access to default HTML ("https://localhost:7184/default.html" is always 404)

Please help me!

CodePudding user response:

I think you need to add app.UseFileServer();

Excerpt from MSDN docs e.g. Static files in ASP.NET Core

... Call app.UseFileServer to enable the serving of static files and the default file.

Your call to app.UseDefaultFiles() should not require the "/default.html" parameter since the documentation says: ... With UseDefaultFiles, requests to a folder in wwwroot search for: default.htm default.html index.htm index.html

CodePudding user response:

you need to reverse the order

app.UseStaticFiles();
app.UseDefaultFiles("/default.html");

updated:

you don't need to call app.UseDefaultFiles("/default.html"); at all

  • Related