When creating a WebAPI project using the default template, you might want to serve static HTML files directly from the base URL. To achieve this, add UseDefaultFiles()
and UseStaticFiles()
in the correct order, as shown below:
app.UseDefaultFiles();
app.UseStaticFiles();
It is crucial to maintain the correct order of these middleware calls. If UseStaticFiles()
is placed before UseDefaultFiles()
, entering the base service URL in the browser will not automatically route to index.html
. Instead, a "Not Found" error will be returned.
ยฉ 2025 juniyunapapa@gmail.com.