问题
I need to be able to serve my 'index.html', under the default url /, using Kestrel web server. Right now I'm only able to access my static files with the full path i.e /index.html
Again this works perfectly on VisualStudio, the context is OSX with Kestrel
This is my Startup.cs
public void ConfigureServices(DI.IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseMvc();
}
The solution I have so far, is to do a redirect inside a HomeController. But this is plain ugly, I'm trying to serve an static html file, which I honestly don't want it to be handled by my Application, if possible served directly from Kestrel.
回答1:
You need to enable the DefaultFilesMiddleware
using UseDefaultFiles()
and place it before the call to UseStaticFiles()
:
app.UseDefaultFiles();
app.UseStaticFiles();
If you don't specify otherwise, the middleware uses the DefaultFilesOptions
by default, which means this list of default file names will be used:
default.htm
default.html
index.htm
index.html
See MSDN
来源:https://stackoverflow.com/questions/30228620/kestrel-on-aspnet-vnext-doesnt-serve-index-page-under