Tutorial: Get started with Razor Pages in ASP.NET Core
This is the first tutorial of a series. The series teaches the basics of building an ASP.NET Core Razor Pages web app.
For a more advanced introduction aimed at experienced developers, see Introduction to Razor Pages.
At the end of the series you'll have an app that manages a database of movies.
In this tutorial, you:
- Create a Razor Pages web app.
- Run the app.
- Examine the project files.
At the end of this tutorial you'll have a working Razor Pages web app that you'll build on in later tutorials.
Create a Razor Pages web app
From the Visual Studio File menu, select New > Project.
Create a new ASP.NET Core Web Application. Name the project RazorPagesMovie. It's important to name the project RazorPagesMovie so the namespaces will match when you copy and paste code.
Select ASP.NET Core 2.2 in the dropdown, and then select Web Application.
The following starter project is created:
Run the app
Press Ctrl+F5 to run without the debugger.
Visual Studio displays the following dialog:
Select Yes if you trust the IIS Express SSL certificate.
The following dialog is displayed:
Select Yes if you agree to trust the development certificate.
See Trust the ASP.NET Core HTTPS development certificate for more information.
Visual Studio starts IIS Express and runs the app. The address bar shows
localhost:port#and not something like
example.com. That's because
localhostis the standard hostname for the local computer. Localhost only serves web requests from the local computer. When Visual Studio creates a web project, a random port is used for the web server.
On the app's home page, select Accept to consent to tracking.
This app doesn't track personal information, but the project template includes the consent feature in case you need it to comply with the European Union's General Data Protection Regulation (GDPR).
The following image shows the app after you give consent to tracking:
Examine the project files
Here's an overview of the main project folders and files that you'll work with in later tutorials.
Contains Razor pages and supporting files. Each Razor page is a pair of files:
- A .cshtml file that contains HTML markup with C# code using Razor syntax.
- A .cshtml.cs file that contains C# code that handles page events.
Supporting files have names that begin with an underscore. For example, the _Layout.cshtml file configures UI elements common to all pages. This file sets up the navigation menu at the top of the page and the copyright notice at the bottom of the page. For more information, see Layout in ASP.NET Core.
Contains configuration data, such as connection strings. For more information, see Configuration in ASP.NET Core.
Contains the entry point for the program. For more information, see ASP.NET Core Web Host.
Contains code that configures app behavior, such as whether it requires consent for cookies. For more information, see App startup in ASP.NET Core.
In this tutorial, you:
- Created a Razor Pages web app.
- Ran the app.
- Examined the project files.
Advance to the next tutorial in the series:
Send feedback about: