Static files are typically located in the web root (wwwroot) folder.By default, that is the only place where we can serve up files directly from the file system.
1.create a html file inside (wwwroot) name index.html
2.install Microsoft.AspNet.StaticFiles package via NuGet
3.Add UseStaticFiles in Startup.cs under Configure methode
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles(); // For the wwwroot folder
// if you want to run outside wwwroot then use this
//request like http://<app>/StaticFiles/index.html
/* app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
RequestPath = new PathString("/StaticFiles")
});*/
}
if you want to run Static Files outside wwwroot, then-
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles(); // For the wwwroot folder
//request like http://<app>/StaticFiles/index.html
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
RequestPath = new PathString("/StaticFiles")
});
}
your request like http://<app>/StaticFiles/index.html
if you want index.html to be your default file, this is a feature that IIS has always had,then
public void Configure(IApplicationBuilder app) {
app.UseIISPlatformHandler();
app.UseDeveloperExceptionPage();
app.UseRuntimeInfoPage();
app.UseDefaultFiles();
app.UseStaticFiles();
}
hopefully it's help you. You can more information from this link.