Microsoft Docs

Your guide to Microsoft technologies

Getting Started with ASP.NET Core

Welcome to ASP.NET Core! This guide 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 .NET website. This includes the .NET runtime and the C# compiler.
  • Code Editor: A code editor like Visual Studio Code (free and recommended), Visual Studio, or JetBrains Rider.

Installing the .NET SDK

Follow the instructions for your operating system on the .NET download page. After installation, open your terminal or command prompt and verify the installation by running:

dotnet --version

Creating Your First ASP.NET Core Application

We'll create a simple web application using the command line.

  1. Create a project directory:
    mkdir MyFirstAspNetCoreApp
    cd MyFirstAspNetCoreApp
  2. Create a new Razor Pages project:
    dotnet new webapp

    This command creates a basic Razor Pages project. If you prefer an MVC project, use dotnet new mvc.

  3. Run the application:
    dotnet run

    This will build and start your application. You'll see output indicating the URL where your application is running, typically https://localhost:5001 or http://localhost:5000. Open this URL in your web browser.

Tip

You can also use Visual Studio to create new ASP.NET Core projects. Simply select "File" > "New" > "Project" and choose the appropriate ASP.NET Core template.

Understanding the Project Structure

When you create a new project, you'll find several key files and folders:

  • Pages/: Contains Razor Pages (.cshtml files) and their code-behind files (.cshtml.cs).
  • wwwroot/: Contains static assets like CSS, JavaScript, and images.
  • appsettings.json: Stores configuration settings for your application.
  • Program.cs: The entry point of your application, where the web host is configured and started.
  • Startup.cs (in older templates) or configuration within Program.cs (in .NET 6+): Configures application services and the HTTP request pipeline.

Note

The structure and configuration approach have evolved with .NET versions. For .NET 6 and later, the web host is configured directly in Program.cs, simplifying the startup process.

Next Steps

Now that you have a basic application running, you can explore further: