Advertisements

Startup Page In ASP.NET Core


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

In this way, we can implement the default startup page In ASP.NET Core.

  • Default Configuration
  • Customized Configuration

Default Configuration

We can use UseDefaultFiles() extension method in ASP.NET Core. 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. Thus, we can use DefaultFilesOptions in ASP.NET Core. If you want to run other files as default, check the code give below in Startup.Cs.

Code

DefaultFilesOptions DefaultFile = new DefaultFilesOptions();
DefaultFile.DefaultFileNames.Clear();
DefaultFile.DefaultFileNames.Add("Welcome.html");
app.UseDefaultFiles(DefaultFile);
app.UseStaticFiles();

Reference

Summary

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: