23

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.

DavidG
  • 113,891
  • 12
  • 217
  • 223
Javier
  • 672
  • 5
  • 13

1 Answers1

42

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

haim770
  • 48,394
  • 7
  • 105
  • 133
  • 1
    This is a good answer, I marked it solved, although it still doesnt do it for me. The empty / url is still not serving. I'm still thinking it may be related to the Kestrel Server somehow. – Javier May 14 '15 at 15:37
  • 7
    Try to call `UseDefaultFiles()` *before* `UseStaticFiles()`. Also, see https://github.com/aspnet/StaticFiles/issues/10 – haim770 May 14 '15 at 15:50
  • 1
    you totally got it!, I will suggest the previous comment as part of the answer – Javier May 14 '15 at 16:40
  • 3
    One thing I was completely missing is that the _html_ file has to reside in a **folder** named wwwroot, it may not be placed in the project root as previously in ASP.NET, if it might help anyone :) – Marcus May 11 '16 at 12:09