2016-10-29 01:35:15 +08:00
---
2018-05-11 00:40:06 +08:00
title: Get started with ASP.NET Core
2023-04-11 02:58:13 +08:00
author: tdykstra
2022-03-09 04:26:08 +08:00
description: A short tutorial using the .NET CLI to create and run a basic Hello World app using ASP.NET Core.
2022-02-23 19:11:44 +08:00
monikerRange: ">= aspnetcore-3.1"
2018-01-29 23:21:31 +08:00
ms.author: riande
2018-05-11 00:40:06 +08:00
ms.custom: mvc
2022-03-09 04:26:08 +08:00
ms.date: 03/07/2022
2016-10-29 01:35:15 +08:00
uid: getting-started
---
2018-10-05 05:12:56 +08:00
# Tutorial: Get started with ASP.NET Core
2020-02-21 04:02:47 +08:00
This tutorial shows how to create and run an ASP.NET Core web app using the .NET Core CLI.
2018-12-04 06:52:20 +08:00
You'll learn how to:
2018-10-05 05:12:56 +08:00
> [!div class="checklist"]
> * Create a web app project.
2019-05-14 09:47:05 +08:00
> * Trust the development certificate.
2018-10-05 05:12:56 +08:00
> * Run the app.
> * Edit a Razor page.
At the end, you'll have a working web app running on your local machine.
2022-02-23 19:11:44 +08:00
:::image source="_static/home-page.png" alt-text="Web app home page":::
2018-10-05 05:12:56 +08:00
## Prerequisites
2018-10-02 02:12:20 +08:00
2022-02-23 19:11:44 +08:00
:::moniker range=">= aspnetcore-6.0"
[!INCLUDE[ ](~/includes/6.0-SDK.md )]
:::moniker-end
:::moniker range=">= aspnetcore-5.0 < aspnetcore-6.0 "
[!INCLUDE[ ](~/includes/5.0-SDK.md )]
:::moniker-end
:::moniker range="< aspnetcore-5.0 "
2020-01-08 07:52:20 +08:00
[!INCLUDE[ ](~/includes/3.1-SDK.md )]
2022-02-23 19:11:44 +08:00
:::moniker-end
2018-05-31 03:48:08 +08:00
2018-10-05 05:12:56 +08:00
## Create a web app project
2018-05-31 03:48:08 +08:00
2018-12-04 06:52:20 +08:00
Open a command shell, and enter the following command:
2018-05-31 03:48:08 +08:00
2019-09-18 05:01:04 +08:00
```dotnetcli
2018-12-04 06:52:20 +08:00
dotnet new webapp -o aspnetcoreapp
```
2018-05-31 03:48:08 +08:00
2019-09-23 08:46:16 +08:00
The preceding command:
* Creates a new web app.
2022-02-23 19:11:44 +08:00
* The `-o aspnetcoreapp` parameter creates a directory named `aspnetcoreapp` with the source files for the app.
2019-09-23 08:46:16 +08:00
2019-05-14 09:47:05 +08:00
### Trust the development certificate
2018-10-05 05:12:56 +08:00
2018-12-04 06:52:20 +08:00
Trust the HTTPS development certificate:
2018-06-03 03:42:05 +08:00
# [Windows](#tab/windows)
2019-09-18 05:01:04 +08:00
```dotnetcli
2018-12-04 06:52:20 +08:00
dotnet dev-certs https --trust
```
2018-06-03 03:42:05 +08:00
2018-12-04 06:52:20 +08:00
The preceding command displays the following dialog:
2018-06-03 03:42:05 +08:00
2022-02-23 19:11:44 +08:00
:::image source="~/getting-started/_static/cert.png" alt-text="Security warning dialog":::
2018-06-03 03:42:05 +08:00
2018-12-04 06:52:20 +08:00
Select **Yes** if you agree to trust the development certificate.
2018-06-03 03:42:05 +08:00
# [macOS](#tab/macos)
2019-09-18 05:01:04 +08:00
```dotnetcli
2018-12-04 06:52:20 +08:00
dotnet dev-certs https --trust
```
2018-06-03 03:42:05 +08:00
2018-12-04 06:52:20 +08:00
The preceding command displays the following message:
2018-05-31 03:48:08 +08:00
2022-02-23 19:11:44 +08:00
*Trusting the HTTPS development certificate was requested. If the certificate isn't already trusted, we'll run the following command:* `'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain <<certificate>>'`
2019-03-13 09:49:51 +08:00
2019-03-19 22:42:44 +08:00
This command might prompt you for your password to install the certificate on the system keychain. Enter your password if you agree to trust the development certificate.
2018-06-03 03:42:05 +08:00
# [Linux](#tab/linux)
2018-12-04 06:52:20 +08:00
See the documentation for your Linux distribution on how to trust the HTTPS development certificate.
2018-06-03 03:42:05 +08:00
---
2019-02-27 07:04:59 +08:00
For more information, see [Trust the ASP.NET Core HTTPS development certificate ](xref:security/enforcing-ssl#trust-the-aspnet-core-https-development-certificate-on-windows-and-macos )
2018-10-05 05:12:56 +08:00
## Run the app
2016-10-29 01:35:15 +08:00
2018-12-04 06:52:20 +08:00
Run the following commands:
2016-10-29 01:35:15 +08:00
2019-09-18 05:01:04 +08:00
```dotnetcli
2018-12-04 06:52:20 +08:00
cd aspnetcoreapp
2019-09-27 03:39:53 +08:00
dotnet watch run
2018-12-04 06:52:20 +08:00
```
2016-10-29 01:35:15 +08:00
2022-07-22 05:21:38 +08:00
After the command shell indicates that the app has started, browse to `https://localhost:{port}` , where `{port}` is the random port used.
2018-05-08 04:25:07 +08:00
2018-10-05 05:12:56 +08:00
## Edit a Razor page
2018-05-11 00:40:06 +08:00
2022-02-23 19:11:44 +08:00
Open `Pages/Index.cshtml` and modify and save the page with the following highlighted markup:
2018-05-08 04:25:07 +08:00
2022-02-23 19:11:44 +08:00
:::code language="cshtml" source="sample/index.cshtml" highlight="9":::
2018-05-08 04:25:07 +08:00
2022-07-22 05:21:38 +08:00
Browse to `https://localhost:{port}` , refresh the page, and verify the changes are displayed.
2018-05-08 04:25:07 +08:00
2018-10-05 05:12:56 +08:00
## Next steps
2018-05-08 04:25:07 +08:00
2018-10-05 05:12:56 +08:00
In this tutorial, you learned how to:
2018-05-08 04:25:07 +08:00
2018-10-05 05:12:56 +08:00
> [!div class="checklist"]
> * Create a web app project.
2019-05-14 09:47:05 +08:00
> * Trust the development certificate.
2018-10-05 05:12:56 +08:00
> * Run the project.
> * Make a change.
2018-05-08 04:25:07 +08:00
2022-03-09 04:26:08 +08:00
To learn more about ASP.NET Core, see the following:
2018-09-17 03:14:07 +08:00
2018-10-05 05:12:56 +08:00
> [!div class="nextstepaction"]
2019-02-23 04:44:53 +08:00
> <xref:index#recommended-learning-path>