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"
|
2024-04-10 06:18:55 +08:00
|
|
|
ms.author: tdykstra
|
2018-05-11 00:40:06 +08:00
|
|
|
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
|
|
|
|
---
|
2018-10-05 05:12:56 +08:00
|
|
|
# Tutorial: Get started with ASP.NET Core
|
|
|
|
|
2024-08-01 00:50:11 +08:00
|
|
|
[!INCLUDE[](~/includes/not-latest-version.md)]
|
|
|
|
|
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
|
|
|
|
2024-09-18 17:58:22 +08:00
|
|
|
For Blazor tutorials, see <xref:blazor/tutorials/index>.
|
|
|
|
|
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.
|
|
|
|
> * 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
|
|
|
|
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"
|
2023-04-12 06:18:37 +08:00
|
|
|
[!INCLUDE[](~/includes/7.0-SDK.md)]
|
|
|
|
:::moniker-end
|
2024-05-30 10:11:39 +08:00
|
|
|
:::moniker range="<= aspnetcore-6.0"
|
2022-02-23 19:11:44 +08:00
|
|
|
[!INCLUDE[](~/includes/6.0-SDK.md)]
|
|
|
|
:::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
|
2024-05-30 10:21:25 +08:00
|
|
|
dotnet new webapp --output aspnetcoreapp --no-https
|
2018-12-04 06:52:20 +08:00
|
|
|
```
|
2018-05-31 03:48:08 +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.
|
2019-09-23 08:46:16 +08:00
|
|
|
|
2024-05-30 10:11:39 +08:00
|
|
|
## Run the app
|
2018-06-03 03:42:05 +08:00
|
|
|
|
2024-05-30 10:11:39 +08:00
|
|
|
Run the following commands:
|
2018-06-03 03:42:05 +08:00
|
|
|
|
2019-09-18 05:01:04 +08:00
|
|
|
```dotnetcli
|
2024-05-30 10:11:39 +08:00
|
|
|
cd aspnetcoreapp
|
|
|
|
dotnet run
|
2018-12-04 06:52:20 +08:00
|
|
|
```
|
2018-06-03 03:42:05 +08:00
|
|
|
|
2024-06-01 07:53:52 +08:00
|
|
|
The `run` command produces output like the following example:
|
2018-06-03 03:42:05 +08:00
|
|
|
|
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
|
|
|
```
|
2018-06-03 03:42:05 +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`.
|
2019-03-13 09:49:51 +08:00
|
|
|
|
2024-05-30 10:11:39 +08:00
|
|
|
The browser shows the home page.
|
2018-06-03 03:42:05 +08:00
|
|
|
|
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:
|
2018-05-08 04:25:07 +08:00
|
|
|
|
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:
|
2018-05-11 00:40:06 +08:00
|
|
|
|
2024-05-30 10:11:39 +08:00
|
|
|
:::code language="cshtml" source="sample/index.cshtml" highlight="9":::
|
2018-05-08 04:25:07 +08:00
|
|
|
|
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.
|
2018-05-08 04:25:07 +08:00
|
|
|
|
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.":::
|
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.
|
|
|
|
> * 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>
|