AspNetCore.Docs/aspnetcore/getting-started/index.md

122 lines
3.5 KiB
Markdown
Raw Normal View History

2016-10-29 01:35:15 +08:00
---
title: Get started with ASP.NET Core
2016-10-29 01:35:15 +08:00
author: rick-anderson
description: A short tutorial that creates and runs a basic Hello World app using ASP.NET Core.
monikerRange: ">= aspnetcore-3.1"
2018-01-29 23:21:31 +08:00
ms.author: riande
ms.custom: mvc
ms.date: 02/23/2022
no-loc: ["Blazor Hybrid", Home, Privacy, Kestrel, appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR]
2016-10-29 01:35:15 +08:00
uid: getting-started
---
# 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:
> [!div class="checklist"]
> * Create a web app project.
> * Trust the development certificate.
> * Run the app.
> * Edit a Razor page.
At the end, you'll have a working web app running on your local machine.
:::image source="_static/home-page.png" alt-text="Web app home page":::
## Prerequisites
:::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"
[!INCLUDE[](~/includes/3.1-SDK.md)]
:::moniker-end
## Create a web app project
2018-12-04 06:52:20 +08:00
Open a command shell, and enter the following command:
```dotnetcli
2018-12-04 06:52:20 +08:00
dotnet new webapp -o aspnetcoreapp
```
The preceding command:
* Creates a new web app.
* The `-o aspnetcoreapp` parameter creates a directory named `aspnetcoreapp` with the source files for the app.
### Trust the development certificate
2018-12-04 06:52:20 +08:00
Trust the HTTPS development certificate:
# [Windows](#tab/windows)
```dotnetcli
2018-12-04 06:52:20 +08:00
dotnet dev-certs https --trust
```
2018-12-04 06:52:20 +08:00
The preceding command displays the following dialog:
:::image source="~/getting-started/_static/cert.png" alt-text="Security warning dialog":::
2018-12-04 06:52:20 +08:00
Select **Yes** if you agree to trust the development certificate.
# [macOS](#tab/macos)
```dotnetcli
2018-12-04 06:52:20 +08:00
dotnet dev-certs https --trust
```
2018-12-04 06:52:20 +08:00
The preceding command displays the following message:
*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-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.
# [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.
---
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)
## 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
```dotnetcli
2018-12-04 06:52:20 +08:00
cd aspnetcoreapp
dotnet watch run
2018-12-04 06:52:20 +08:00
```
2016-10-29 01:35:15 +08:00
2020-03-31 09:42:14 +08:00
After the command shell indicates that the app has started, browse to `https://localhost:5001`.
## Edit a Razor page
Open `Pages/Index.cshtml` and modify and save the page with the following highlighted markup:
:::code language="cshtml" source="sample/index.cshtml" highlight="9":::
2020-03-31 09:42:14 +08:00
Browse to `https://localhost:5001`, refresh the page, and verify the changes are displayed.
## Next steps
In this tutorial, you learned how to:
> [!div class="checklist"]
> * Create a web app project.
> * Trust the development certificate.
> * Run the project.
> * Make a change.
2019-02-23 04:44:53 +08:00
To learn more about ASP.NET Core, see the recommended learning path in the introduction:
> [!div class="nextstepaction"]
2019-02-23 04:44:53 +08:00
> <xref:index#recommended-learning-path>