Your journey into modern web development starts here.
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.
Let's explore some fundamental building blocks of ASP.NET Core applications:
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+)
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+).
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);
}
}
ASP.NET Core supports different patterns for building web applications:
.cshtml file (the UI) and a .cshtml.cs file (the code-behind). Great for simpler scenarios or when you want a more direct mapping between UI and logic.