Getting Started with ASP.NET Core

Welcome to the ASP.NET Core getting started guide! This tutorial will walk you through the essential steps to set up your environment and create your first ASP.NET Core application.

Prerequisites

Before you begin, ensure you have the following installed:

  • .NET SDK: Download and install the latest .NET SDK from the official dotnet.microsoft.com website.
  • Code Editor: Visual Studio Code, Visual Studio, or any other preferred code editor.

Step 1: Create a New Project

You can create a new ASP.NET Core project using the .NET CLI. Open your terminal or command prompt and navigate to the directory where you want to create your project. Then, run the following command:

dotnet new webapp -o MyFirstAspNetCoreApp

This command creates a new web application project named MyFirstAspNetCoreApp in a new directory of the same name.

Step 2: Navigate to the Project Directory

Change your current directory to the newly created project folder:

cd MyFirstAspNetCoreApp

Step 3: Run the Application

To run your application, use the following command:

dotnet run

The output will show you the URL where your application is running, typically https://localhost:5001 and http://localhost:5000.

Step 4: Explore the Project Structure

Open the MyFirstAspNetCoreApp folder in your code editor. You'll see a structure similar to this:

MyFirstAspNetCoreApp/
├── Controllers/
├── Pages/
│   ├── _ViewImports.cshtml
│   ├── _ViewStart.cshtml
│   ├── Error.cshtml
│   └── Index.cshtml
├── Properties/
│   └── launchSettings.json
├── wwwroot/
│   ├── css/
│   ├── js/
│   └── index.html
├── appsettings.Development.json
├── appsettings.json
├── Program.cs
├── Startup.cs
└── MyFirstAspNetCoreApp.csproj
  • Pages/Index.cshtml: This is the default page that will be displayed when you run the application.
  • Startup.cs: Contains the application's startup configuration.
  • appsettings.json: Configuration settings.
  • .csproj file: Defines project properties and dependencies.

Step 5: Make a Change

Let's make a small change to the Pages/Index.cshtml file. Open it and modify the main heading:

<h1>Hello, ASP.NET Core World!</h1>

Save the file and refresh your browser pointed to the application's URL. You should see your updated heading.

Congratulations!

You've successfully created and run your first ASP.NET Core application. From here, you can explore building more complex web applications using ASP.NET Core's robust features.

Next Steps