aspnetcore/tutorials/razor-pages/razor-pages-start/includes/razor-pages-start6.md
:::moniker range="= aspnetcore-6.0" This is the first tutorial of a series that teaches the basics of building an ASP.NET Core Razor Pages web app.
For a more advanced introduction aimed at developers who are familiar with controllers and views, see Introduction to Razor Pages. For a video introduction, see Entity Framework Core for Beginners.
[!INCLUDE Choose web UI]
At the end of the series, you'll have an app that manages a database of movies.
In this tutorial, you:
[!div class="checklist"]
- 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 enhance in later tutorials.
Start Visual Studio 2022 and select Create a new project.
In the Create a new project dialog, select ASP.NET Core Web App, and then select Next.
In the Configure your new project dialog, enter RazorPagesMovie for Project name. It's important to name the project RazorPagesMovie, including matching the capitalization, so the namespaces will match when you copy and paste example code.
Select Next.
In the Additional information dialog, select .NET 6.0 (Long-term support) and then select Create.
The following starter project is created:
The tutorial assumes familiarity with VS Code. For more information, see Getting started with VS Code.
Select New Terminal from the Terminal menu to open the integrated terminal.
Change to the directory (cd) that will contain the project.
Run the following commands:
dotnet new webapp -o RazorPagesMovie
code -r RazorPagesMovie
The dotnet new command creates a new Razor Pages project in the RazorPagesMovie folder.
The code command opens the RazorPagesMovie project folder in the current instance of Visual Studio Code.
Select File > New Solution.
In Visual Studio 2022 for Mac select Web and Console > App > Web Application > Next.
In the Configure your new Web Application dialog:
Name the project RazorPagesMovie and select Create.
Select RazorPagesMovie in Solution Explorer, and then press Ctrl+F5 to run without the debugger.
Visual Studio displays the following dialog when a project is not yet configured to use SSL:
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.
[!INCLUDEtrust FF]
Visual Studio:
https://localhost:5001, which displays the apps UI.In Visual Studio Code, press Ctrl+F5 to run the app. At the Select environment prompt, select .NET Core.
The default browser launched with the following URL: https://localhost:5001
Select Debug > Start Debugging to launch the app. Visual Studio for Mac launches a browser and navigates to https://localhost:<port>, where <port> is the port number randomly assigned at project creation and is set in Properties/launchSettings.json.
The following sections contain 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:
.cshtml file that has HTML markup with C# code using Razor syntax..cshtml.cs file that has 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 xref:mvc/views/layout.
Contains static assets, like HTML files, JavaScript files, and CSS files. For more information, see xref:fundamentals/static-files.
appsettings.jsonContains configuration data, like connection strings. For more information, see xref:fundamentals/configuration/index.
Contains the following code:
The following lines of code in this file create a WebApplicationBuilder with preconfigured defaults, add Razor Pages support to the Dependency Injection (DI) container, and build the app:
The developer exception page is enabled by default and provides helpful information on exceptions. Production apps should not be run in development mode because the developer exception page can leak sensitive information.
The following code sets the exception endpoint to /Error and enables HTTP Strict Transport Security Protocol (HSTS) when the app is not running in development mode:
For example, the preceding code runs when the app is in production or test mode. For more information, see Use multiple environments in ASP.NET Core.
The following code enables various Middleware:
app.UseHttpsRedirection(); : Redirects HTTP requests to HTTPS.app.UseStaticFiles(); : Enables static files, such as HTML, CSS, images, and JavaScript to be served. For more information, see xref:fundamentals/static-files.app.UseRouting(); : Adds route matching to the middleware pipeline. For more information, see xref:fundamentals/routingapp.MapRazorPages();: Configures endpoint routing for Razor Pages.app.UseAuthorization(); : Authorizes a user to access secure resources. This app doesn't use authorization, therefore this line could be removed.app.Run(); : Runs the app.If you run into a problem you can't resolve, compare your code to the completed project. View or download completed project (how to download).
[!div class="step-by-step"] Next: Add a model
:::moniker-end