Add a New Page to ASP.NET Core Razor Project

Adding pages to an ASP.NET Core Razor pages application is a process that you might need to go through many times, and it probably sounds like something simple, but that is not always the case.

This post will show you how to add a new ASP.NET page to an existing ASP.NET Core Razor page application.

Create a new Page

If you need to create a new page using the .NET CLI, open the project directory Pages folder (see screenshot) and run the command below.

dotnet new page --name mycode

In our case, we added a page called mycode.

How does it work?

Behind the scenes, ASP.NET uses a method called MapRazorPages() that maps any page added to the Pages/ to the routing template using attribute routing.

       app.UseEndpoints(endpoints =>

Once you add the page, you can go ahead, run the app and access it. The process is straightforward if you don’t need a custom routing that routes multiple URLs to the same page.