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

106 lines
2.8 KiB
Markdown
Raw Normal View History

2016-10-29 01:35:15 +08:00
---
title: Get started with ASP.NET Core
author: tdykstra
description: A short tutorial using the .NET CLI to create and run a basic Hello World app using ASP.NET Core.
monikerRange: ">= aspnetcore-3.1"
2024-04-10 06:18:55 +08:00
ms.author: tdykstra
ms.custom: mvc
2024-06-01 07:00:27 +08:00
ms.date: 05/31/2024
2016-10-29 01:35:15 +08:00
uid: getting-started
---
# Tutorial: Get started with ASP.NET Core
2024-05-31 02:08:45 +08:00
This tutorial shows how to create and run an ASP.NET Core web app using the .NET CLI.
2018-12-04 06:52:20 +08:00
You'll learn how to:
> [!div class="checklist"]
> * Create a web app project.
> * 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
2024-05-30 10:11:39 +08:00
:::moniker range=">= aspnetcore-8.0"
[!INCLUDE[](~/includes/8.0-SDK.md)]
:::moniker-end
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
[!INCLUDE[](~/includes/7.0-SDK.md)]
:::moniker-end
2024-05-30 10:11:39 +08:00
:::moniker range="<= aspnetcore-6.0"
[!INCLUDE[](~/includes/6.0-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
2024-05-30 10:21:25 +08:00
dotnet new webapp --output aspnetcoreapp --no-https
2018-12-04 06:52:20 +08:00
```
2024-05-30 10:21:25 +08:00
The preceding command creates a new web app project in a directory named `aspnetcoreapp`. The project doesn't use HTTPS.
2024-05-30 10:11:39 +08:00
## Run the app
2024-05-30 10:11:39 +08:00
Run the following commands:
```dotnetcli
2024-05-30 10:11:39 +08:00
cd aspnetcoreapp
dotnet run
2018-12-04 06:52:20 +08:00
```
2024-06-01 07:53:52 +08:00
The `run` command produces output like the following example:
2024-06-01 07:00:27 +08:00
```output
2024-05-30 10:11:39 +08:00
Building...
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5109
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\aspnetcoreapp
2018-12-04 06:52:20 +08:00
```
2024-05-30 10:11:39 +08:00
Open a browser and go to the URL shown in the output. In this example, the URL is `http://localhost:5109`.
2024-05-30 10:11:39 +08:00
The browser shows the home page.
2024-05-30 10:11:39 +08:00
:::image source="_static/home-page.png" alt-text="Web app home page":::
2016-10-29 01:35:15 +08:00
2024-05-30 10:11:39 +08:00
## Edit a Razor page
2016-10-29 01:35:15 +08:00
2024-05-30 10:11:39 +08:00
Change the home page:
2024-06-01 07:00:27 +08:00
* In the command shell, press Ctrl+C (Cmd+C in macOS) to exit the program.
2024-05-30 10:11:39 +08:00
* Open `Pages/Index.cshtml` in a text editor.
* Replace the line that begins with "Learn about" with the following highlighted markup and code:
2024-05-30 10:11:39 +08:00
:::code language="cshtml" source="sample/index.cshtml" highlight="9":::
2024-05-30 10:11:39 +08:00
* Save your changes.
* In the command shell run the `dotnet run` command again.
* In the browser, refresh the page and verify the changes are displayed.
2024-05-30 10:11:39 +08:00
:::image source="_static/home-page-changed.png" alt-text="Web app home page showing the change that was made.":::
## Next steps
In this tutorial, you learned how to:
> [!div class="checklist"]
> * Create a web app project.
> * Run the project.
> * Make a change.
To learn more about ASP.NET Core, see the following:
> [!div class="nextstepaction"]
2019-02-23 04:44:53 +08:00
> <xref:index#recommended-learning-path>