[ASP.NET] Configuring Static File Hosting in a WebAPI Project

발행일: Feb, 2025
조회수: 0
단어수: 94

Table of Contents

Setting Up Static File Routing

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();

The Importance of Order

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.


태그#WebAPI#Static Files#UseDefaultFiles#UseStaticFiles#ASP.NET Core#Hosting

JUNA BLOG VISITORS

오늘0
Total0