ASP.NET Core Basics

This document provides an introduction to the fundamental concepts of ASP.NET Core, a cross-platform, high-performance, open-source framework for building modern, cloud-based, internet-connected applications.

What is ASP.NET Core?

ASP.NET Core is a re-architected version of ASP.NET that:

Key Concepts

Project Structure

A typical ASP.NET Core project includes the following key files and folders:

The Request Pipeline

ASP.NET Core uses a middleware pipeline to handle HTTP requests. Middleware components are executed in a specific order to process requests and responses. Common middleware includes:

Note: The order of middleware in the pipeline is crucial for correct application behavior.

Dependency Injection

ASP.NET Core has built-in support for Dependency Injection (DI), making it easier to manage dependencies and write loosely coupled code. Services are registered with the DI container and can be injected into controllers, Razor Pages, or other services.

// Example of registering a service in Program.cs
builder.Services.AddScoped();

Configuration

ASP.NET Core supports multiple configuration sources, including JSON files, environment variables, command-line arguments, and Azure Key Vault. This allows you to manage application settings effectively across different environments.

Tip: Use appsettings.json for development and environment-specific configuration files (e.g., appsettings.Development.json) for overrides.

Getting Started

To start building an ASP.NET Core application, you typically need:

  1. The .NET SDK installed on your machine.
  2. A code editor like Visual Studio, VS Code, or JetBrains Rider.
  3. Create a new project using the .NET CLI:
dotnet new webapp -o MyAspNetCoreApp
cd MyAspNetCoreApp
dotnet run

This will create a basic web application and run it, allowing you to explore the project structure and begin developing your application.

Next Steps

Explore the following topics to deepen your understanding of ASP.NET Core: