Kestrel on AspNet vNext doesnt serve index page under /

谁都会走 提交于 2019-12-08 15:43:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!