๐Ÿ˜œ

์ญˆ๋‚˜์•„๋น  ๋ธ”๋กœ๊ทธ

JUNA
STUDIO

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

๋ฐœํ–‰์ผ: Feb, 2025
์กฐํšŒ์ˆ˜: 3
๋‹จ์–ด์ˆ˜: 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.


Tags: #WebAPI#Static Files#UseDefaultFiles#UseStaticFiles#ASP.NET Core#Hosting
JUNA BLOG VISITORS
Today
7
 (
updown
-7
)
Total
657
 (
updown
+7
)

ยฉ 2025 juniyunapapa@gmail.com.