2016-10-29 01:35:15 +08:00
---
2018-05-11 00:40:06 +08:00
title: Get started with ASP.NET Core
2016-10-29 01:35:15 +08:00
author: rick-anderson
2017-08-09 07:22:51 +08:00
description: A quick tutorial that creates and runs a simple Hello World app using ASP.NET Core.
2018-01-29 23:21:31 +08:00
ms.author: riande
2018-05-11 00:40:06 +08:00
ms.custom: mvc
2018-06-21 01:10:56 +08:00
ms.date: 05/31/2018
2016-10-29 01:35:15 +08:00
uid: getting-started
---
2018-05-11 00:40:06 +08:00
# Get started with ASP.NET Core
2016-10-29 01:35:15 +08:00
2018-10-02 02:12:20 +08:00
This document provides steps for creating and running an ASP.NET Core app.
2018-05-31 03:48:08 +08:00
::: moniker range=">= aspnetcore-2.1"
2018-06-28 00:07:58 +08:00
1. Install the [!INCLUDE [ ](~/includes/2.1-SDK.md )].
2018-05-31 03:48:08 +08:00
2018-06-03 03:42:05 +08:00
2. Create an ASP.NET Core project. Open a command shell and enter the following command:
2018-05-31 03:48:08 +08:00
2018-10-02 00:16:40 +08:00
```console
dotnet new webapp -o aspnetcoreapp
```
2018-05-31 03:48:08 +08:00
2018-06-03 03:42:05 +08:00
3. Trust the HTTPS development certificate:
# [Windows](#tab/windows)
2018-10-02 00:16:40 +08:00
```console
dotnet dev-certs https --trust
```
2018-06-03 03:42:05 +08:00
2018-10-02 00:16:40 +08:00
The preceding command displays the following dialog:
2018-06-03 03:42:05 +08:00
2018-10-02 00:16:40 +08:00
![Security warning dialog ](_static/cert.png )
2018-06-03 03:42:05 +08:00
2018-10-02 00:16:40 +08:00
Select **Yes** if you agree to trust the development certificate.
2018-06-03 03:42:05 +08:00
# [macOS](#tab/macos)
2018-10-02 00:16:40 +08:00
```console
dotnet dev-certs https --trust
```
2018-06-03 03:42:05 +08:00
2018-10-02 00:16:40 +08:00
The preceding command displays the following message:
2018-05-31 03:48:08 +08:00
2018-10-02 00:16:40 +08:00
*Trusting the HTTPS development certificate was requested. If the certificate is not already trusted we will run the following command:* `'sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain <<certificate>>'` .
*This command might prompt you for your password to install the certificate on the system keychain.
Password:*
2018-06-03 03:42:05 +08:00
2018-10-02 00:16:40 +08:00
Enter your password if you agree to trust the development certificate.
2018-06-03 03:42:05 +08:00
# [Linux](#tab/linux)
2018-10-02 02:12:20 +08:00
See the documentation for your Linux distribution on how to trust the HTTPS development certificate.
2018-09-17 03:12:56 +08:00
2018-06-03 03:42:05 +08:00
---
4. Run the app:
2018-10-02 00:16:40 +08:00
```console
cd aspnetcoreapp
dotnet run
```
2018-05-31 03:48:08 +08:00
2018-06-03 03:42:05 +08:00
5. Browse to [http://localhost:5001 ](http://localhost:5001 ). Click **Accept** to accept the privacy and cookie policy. This app doesn't keep personal information.
2018-05-31 03:48:08 +08:00
2018-06-03 03:42:05 +08:00
6. Open *Pages/About.cshtml* and modify the page with the following highlighted markup:
2018-05-31 03:48:08 +08:00
2018-10-02 00:16:40 +08:00
[!code-cshtml[ ](sample/getting-started/about.cshtml?highlight=9 )]
2018-05-31 03:48:08 +08:00
2018-06-03 03:42:05 +08:00
7. Browse to [http://localhost:5001/About ](http://localhost:5001/About ) and verify the changes are displayed.
2018-05-31 03:48:08 +08:00
2018-06-28 00:07:58 +08:00
[!INCLUDE [next steps ](~/includes/getting-started/next-steps.md )]
2018-05-31 03:48:08 +08:00
::: moniker-end
::: moniker range="= aspnetcore-2.0"
2016-10-29 01:35:15 +08:00
2018-06-28 00:07:58 +08:00
1. Install the [!INCLUDE [ ](~/includes/net-core-sdk-download-link.md )].
2017-08-09 07:22:51 +08:00
2018-06-03 03:42:05 +08:00
2. Create a new ASP.NET Core project.
2016-10-29 01:35:15 +08:00
2018-06-03 03:42:05 +08:00
Open a command shell. Enter the following command:
2017-08-09 07:22:51 +08:00
2018-10-02 00:16:40 +08:00
```console
dotnet new razor -o aspnetcoreapp
```
2016-10-29 01:35:15 +08:00
2018-05-11 00:40:06 +08:00
3. Run the app with the following commands:
2016-10-29 01:35:15 +08:00
2018-10-02 00:16:40 +08:00
```console
cd aspnetcoreapp
dotnet run
```
2016-10-29 01:35:15 +08:00
2018-05-11 00:40:06 +08:00
4. Browse to [http://localhost:5000 ](http://localhost:5000 ).
2017-09-07 05:57:00 +08:00
2018-05-11 00:40:06 +08:00
5. Open *Pages/About.cshtml* and modify the page to display the message "Hello, world! The time on the server is @DateTime .Now":
2017-09-07 05:57:00 +08:00
2018-10-02 00:16:40 +08:00
[!code-cshtml[ ](sample/getting-started/about.cshtml?highlight=9&range=1-9 )]
2017-09-07 05:57:00 +08:00
2018-04-05 07:51:35 +08:00
6. Browse to [http://localhost:5000/About ](http://localhost:5000/About ) and verify the changes.
2016-10-29 01:35:15 +08:00
2018-06-28 00:07:58 +08:00
[!INCLUDE [next steps ](~/includes/getting-started/next-steps.md )]
2018-05-31 03:48:08 +08:00
2018-05-08 04:25:07 +08:00
::: moniker-end
2018-05-11 00:40:06 +08:00
::: moniker range="< = aspnetcore-1.1"
2018-05-08 04:25:07 +08:00
1. Install the .NET Core **SDK Installer** for SDK 1.0.4 from the [.NET Core All Downloads page ](https://www.microsoft.com/net/download/all ).
2018-06-03 03:42:05 +08:00
2. Create a folder for a new ASP.NET Core project.
2018-05-08 04:25:07 +08:00
2018-06-03 03:42:05 +08:00
Open a command shell. Enter the following commands:
2018-05-08 04:25:07 +08:00
2018-06-03 03:42:05 +08:00
```console
2018-05-08 04:25:07 +08:00
mkdir aspnetcoreapp
cd aspnetcoreapp
```
2018-05-11 00:40:06 +08:00
3. If you have installed a later SDK version on your machine, create a *global.json* file to select the 1.0.4 SDK.
2018-05-08 04:25:07 +08:00
```json
{
"sdk": { "version": "1.0.4" }
}
```
2018-06-03 03:42:05 +08:00
4. Create a new ASP.NET Core project.
2018-05-08 04:25:07 +08:00
2018-06-03 03:42:05 +08:00
```console
2018-05-08 04:25:07 +08:00
dotnet new web
```
2018-05-11 00:40:06 +08:00
5. Restore the packages.
2018-05-08 04:25:07 +08:00
2018-10-02 00:16:40 +08:00
```console
dotnet restore
```
2018-05-08 04:25:07 +08:00
2018-05-11 00:40:06 +08:00
6. Run the app.
2018-05-08 04:25:07 +08:00
2018-06-03 03:42:05 +08:00
```console
2018-05-08 04:25:07 +08:00
dotnet run
```
2018-05-11 00:40:06 +08:00
The [dotnet run ](/dotnet/core/tools/dotnet-run ) command builds the app first, if needed.
2018-05-08 04:25:07 +08:00
2018-05-11 00:40:06 +08:00
7. Browse to `http://localhost:5000` .
2018-05-08 04:25:07 +08:00
2018-06-28 00:07:58 +08:00
[!INCLUDE [next steps ](~/includes/getting-started/next-steps.md )]
2018-09-17 03:14:07 +08:00
2018-06-03 03:42:05 +08:00
::: moniker-end