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.
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.
Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With