© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago
Alex

Serve SPA (React) in ASP.NET web API

Is it a correct way to serve SPA in ASP.NET Web API project? Is there a better way to do it? The way I do it is to move React built to wwwroot and add lines to
useStaticFiles
useStaticFiles
and
MapFallbackToFile
MapFallbackToFile
to
index.html
index.html


Program.cs
...

var app = builder.Build();

// Configure the HTTP request pipeline.

app.UseSwagger();
app.UseSwaggerUI();

using (var scope = app.Services.CreateScope())
{
    DbInitializer.Seed(scope).Wait();
}

app.UseHttpsRedirection();


app.UseExceptionHandler();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.UseDefaultFiles();
app.UseStaticFiles();
app.MapFallbackToFile("index.html");

app.Run();
...

var app = builder.Build();

// Configure the HTTP request pipeline.

app.UseSwagger();
app.UseSwaggerUI();

using (var scope = app.Services.CreateScope())
{
    DbInitializer.Seed(scope).Wait();
}

app.UseHttpsRedirection();


app.UseExceptionHandler();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.UseDefaultFiles();
app.UseStaticFiles();
app.MapFallbackToFile("index.html");

app.Run();
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Serving SPA on ASP.NET Core MVC Web API
C#CC# / help
3y ago
✅ Authorization in ASP.NET Web Api
C#CC# / help
2y ago
✅ ASP.Net Core Web API
C#CC# / help
6mo ago
✅ Testing in ASP.NET Core Web Api
C#CC# / help
9mo ago