Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kestrel on AspNet vNext doesnt serve index page under /

Tags:

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.

like image 577
Javier Avatar asked May 14 '15 03:05

Javier


People also ask

How do I use Kestrel instead of IIS?

The main difference between IIS and Kestrel is that Kestrel is a cross-platform server. It runs on Linux, Windows, and Mac, whereas IIS is Windows-specific. Another essential difference between the two is that Kestrel is fully open-source, whereas IIS is closed-source and developed and maintained only by Microsoft.

Does ASP.NET Core use Kestrel by default?

Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates.

How do I change the port on my Kestrel?

In VS Code all you need to do is press F5. In Visual Studio you need to select “AFewWaysToSetKestrelPorts” from the list, then press F5. The second profile IIS Express relates to the ports IIS Express will use from inside Visual Studio when that option is selected. In my example, it will use ports 10000 and 10001.


1 Answers

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

like image 100
haim770 Avatar answered Sep 29 '22 10:09

haim770