Introduction to ASP.NET Core

Your journey into modern web development starts here.

Welcome to ASP.NET Core

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, internet-connected applications.

Whether you're building traditional web applications, mobile backends, IoT apps, or microservices, ASP.NET Core provides the tools and flexibility you need.

Why Choose ASP.NET Core?

Key Concepts

Let's explore some fundamental building blocks of ASP.NET Core applications:

1. Project Structure

An ASP.NET Core project typically includes files and folders that organize your code. The most common template is the Razor Pages or MVC web application:


-   MyWebApp/
    ├── Controllers/       (For MVC applications)
    ├── Pages/             (For Razor Pages applications)
    │   ├── _ViewImports.cshtml
    │   ├── _ViewStart.cshtml
    │   ├── Index.cshtml
    │   ├── Index.cshtml.cs
    │   └── ...
    ├── Models/
    ├── Views/             (For MVC applications)
    │   ├── Shared/
    │   ├── Home/
    │   │   └── Index.cshtml
    │   └── ...
    ├── Properties/
    │   └── launchSettings.json
    ├── wwwroot/           (Static files like CSS, JS, images)
    ├── appsettings.json
    ├── Program.cs
    └── Startup.cs         (or Program.cs in .NET 6+)
        

2. The Request Pipeline

When a request hits your ASP.NET Core application, it passes through a series of middleware components. This pipeline is highly configurable:

You configure the pipeline in the Configure method of your Startup.cs (or directly in Program.cs for .NET 6+).

3. Dependency Injection (DI)

ASP.NET Core has built-in support for dependency injection, a design pattern that makes applications more maintainable and testable. Services are registered in the DI container during application startup.


// In Startup.cs (ConfigureServices) or Program.cs
services.AddScoped();

// In a controller or page model
public class MyController : Controller
{
    private readonly IMyService _myService;

    public MyController(IMyService myService)
    {
        _myService = myService;
    }

    public IActionResult Index()
    {
        var data = _myService.GetData();
        return View(data);
    }
}
        

4. Model-View-Controller (MVC) vs. Razor Pages

ASP.NET Core supports different patterns for building web applications:

What's Next?

Ready to build your first ASP.NET Core application? Explore the following: