I've got a very simple angular app project that needs to do nothing more than serve static files from wwwroot
. Here is my Startup.cs
:
public class Startup
{
public void ConfigureServices(IServiceCollection services) { }
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.UseStaticFiles();
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
Whenever I launch the project with IIS Express or web I always have to navigate to /index.html
. How do I make it so that I can just visit the root (/
) and still get index.html
?
Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method.
Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default.
Simply change app.UseStaticFiles();
to app.UseFileServer();
public class Startup
{
public void ConfigureServices(IServiceCollection services) { }
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.UseFileServer();
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
You want to server default files and static files:
public void Configure(IApplicationBuilder application)
{
...
// Enable serving of static files from the wwwroot folder.
application.UseStaticFiles();
// Serve the default file, if present.
application.UseDefaultFiles();
...
}
Alternatively, you can use the UseFileServer
method which does the same thing using a single line, rather than two.
public void Configure(IApplicationBuilder application)
{
...
application.UseFileServer();
...
}
See the documentation for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With