Introduction

I think we all are familiar with the configuration of the default startup page in the previous versions of AP.NET but it’s slightly different in ASP.NET Core applications. In this article, I will explain how to configure the default startup page In ASP.NET
Core.

Default Startup Page Configuration

There are two ways to implement the default startup page in ASP.NET Core.

Default Configuration

Customized Configuration

Before reading this article, you must read the articles given below for ASP.NET Core knowledge.

Default Configuration

We can use UseDefaultFiles() extension method in ASP.NET Core 1.0. UseDefaultFiles() will only search for the files given in "wwwroot". If any of the files are detected first in "wwwroot", the files are run as default in the client browser.

default.html

default.htm

index.html

index.htm

UseDefaultFiles must be called before UseStaticFiles or any other method (app.Run, app.Use) to serve the default file in the client-side browser. As you state UseStaticFiles() method after UseDefaultFiles(), it will run UseStaticFiles() method as a default
and automatically terminates the other files which come after UseStaticFiles() method.

Customized Configuration

In this case, we are calling other customized pages as default startup pages in ASP.NET Core 1.0. Thus, we can use DefaultFilesOptions in ASP.NET Core 1.0. If you want to run other files as default, check the code given below in Startup.cs.

Full Code

The following code contains the full source code of startup page configuration in ASP.NET Core.

usingMicrosoft.AspNetCore.Builder;

usingMicrosoft.AspNetCore.Hosting;

usingMicrosoft.AspNetCore.Http;

usingMicrosoft.Extensions.DependencyInjection;

usingMicrosoft.Extensions.Logging;

namespaceStartupConfig

{

publicclass
Startup

{

// This method gets called by the runtime. Use this method to add services to the container.