Getting Started with ASP.NET Core

This guide will walk you through the essential steps to begin developing web applications with ASP.NET Core, the modern, cross-platform, open-source framework for building web apps and services.

Prerequisites

Before you start, ensure you have the following installed:

  • .NET SDK: Download the latest .NET SDK from the official .NET website.
  • Code Editor: A robust code editor like Visual Studio, Visual Studio Code, or JetBrains Rider is recommended.

Creating Your First ASP.NET Core Application

We'll use the .NET CLI to create a new web application. Open your terminal or command prompt and navigate to the directory where you want to create your project.

dotnet new webapp -o MyWebApp

This command does the following:

  • dotnet new webapp: Creates a new ASP.NET Core web application project.
  • -o MyWebApp: Specifies the output directory for the project to be named MyWebApp.

Navigate into the new project directory:

cd MyWebApp

Running Your Application

To run your application, use the following command in your project directory:

dotnet run

Your application will build and start. The output will show the URL where your application is hosted, typically https://localhost:5001 and http://localhost:5000.

Tip: You can use Visual Studio or Visual Studio Code to open the MyWebApp.csproj file and run the application directly from the IDE.

Understanding the Project Structure

A typical ASP.NET Core web application project has the following structure:

  • Pages/: Contains Razor Pages (if using Razor Pages template).
  • Controllers/: Contains MVC controllers (if using MVC template).
  • wwwroot/: Contains static files like CSS, JavaScript, and images.
  • appsettings.json: Configuration file for application settings.
  • Program.cs: The entry point of your application.
  • Startup.cs: Configures the application's request pipeline and services. (In .NET 6 and later, configuration is often moved directly into Program.cs).

Next Steps

Congratulations! You've successfully created and run your first ASP.NET Core application. From here, you can explore: