I have installed Microsoft.AspNetCore.StaticFiles (NuGet package) and below is the pertinent startup code. I have an index.html file both in the root directory and in a folder called static.
All in all, it seems pretty straightforward... not sure why I'm having trouble.
In debug mode on my localhost... I get:
https://localhost:44331 (404)
https://localhost:44331/index.html (404)
https://localhost:44331/static (404)
https://localhost:44331/static/index.html (200)
https://localhost:44331/api/values (200)
When I publish to an azure web app server, none of the above urls works except:
https://myserver.com/api/values (200)
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
app.UseFileServer();
}
Update per the answer (this worked)
In order to be served correctly, your file should be in wwwroot
folder.
If in wwwroot
you will put your index.html
, then you can access it by htts://localhost:44331/index.html
.