This is making me tear my hair out. I'm trying to create a minimal ASP.NET core 2.0 app, so I create an empty web application in VS 2017, and I run:
> uninstall-package Microsoft.AspNetCore.All
> install-package Microsoft.AspNetCore
> install-package Microsoft.AspNetCore.StaticFiles
My Startup.cs looks like:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
I then create a wwwroot/test.html with these contents:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>HTML</h1>
<p>Hello world!</p>
</body>
</html>
I then create a wwwroot/test.txt with the same contents as test.html. So this appears to be is a bare bones setup that should serve any static files under wwwroot for over 400 known MIME types.
Now when I run this project with F5, it opens to the root URL and displays "Hello World!" as expected, indicating it hit the "terminal middleware delegate". If you add /test.txt to the URL you get the HTML displayed above, again as expected. If you change the URL to /test.html you do not get the HTML file as expected, but instead the standard "Hello World!" message.
I've tried this on two separate machines, same results. Now stop debugging, change test.html to test.htm, try again and test.htm works as expected!
An insane thought occurred to me, that perhaps they simply didn't associate .html with "text/html" in the FileExtensionContentTypeProvider, but nope, there it is. I even tried creating a custom type provider explicitly with this association, but that didn't work either.
Can anyone clue me in as to what is going on here? Or am I the only one going insane here and this example works fine for everyone else?