How To Configure Default Startup Page In ASP.NET Core 1.0

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 blog, I will explain how to configure the default startup page In ASP.NET Core 1.0.
 
Default Startup Page Configuration
 
In this way, we can implement the default startup page In ASP.NET Core 1.0.
  • Default Configuration
  • Customized Configuration
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 Anyother method(app.Run,app.Use) to serve the default file in the client-side Browser. As you mention 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 give below in Startup.Cs
 
Code
  1. DefaultFilesOptions DefaultFile = new DefaultFilesOptions();  
  2.             DefaultFile.DefaultFileNames.Clear();  
  3.             DefaultFile.DefaultFileNames.Add("Welcome.html");  
  4.             app.UseDefaultFiles(DefaultFile);  
  5.             app.UseStaticFiles();  
Reference
Summary

We learned how to configure the default startup page In ASP.NET Core 1.0. I hope, this blog is useful for all ASP.NET Core 1.0 beginners.