ASP.NET Core Basics
Welcome to the fundamental guide to building web applications with ASP.NET Core. This tutorial will introduce you to the core concepts, architecture, and essential components of this powerful, cross-platform, open-source framework.
What is ASP.NET Core?
ASP.NET Core is a modern, high-performance, and flexible web development framework built by Microsoft. It enables developers to create cloud-ready, internet-connected applications for Windows, macOS, and Linux.
Key Features:
- Cross-Platform: Run your applications on Windows, macOS, and Linux.
- High Performance: Built for speed and efficiency, outperforming many other web frameworks.
- Modular Design: Easily include only the components your application needs.
- Unified MVC and Web API: A single programming model for building both web UIs and APIs.
- Dependency Injection: Built-in support for powerful dependency injection patterns.
- Tag Helpers: Server-side code can be used to build HTML elements in a much more readable way than razor syntax alone.
Project Structure
A typical ASP.NET Core project has a well-defined structure:
MyWebApp/
├── Controllers/
│ └── HomeController.cs
├── Models/
│ └── ErrorViewModel.cs
├── Views/
│ ├── Home/
│ │ └── Index.cshtml
│ └── Shared/
│ └── _Layout.cshtml
├── appsettings.json
├── Program.cs
└── Startup.cs
The Role of `Startup.cs`
The Startup.cs
file is crucial. It contains two main methods:
ConfigureServices(IServiceCollection services)
: Used to register application services with the dependency injection container.Configure(IApplicationBuilder app, IWebHostEnvironment env)
: Used to configure the HTTP request pipeline.

Middleware Pipeline
The request pipeline is a series of middleware components, each responsible for handling a specific aspect of the request or response. Middleware is executed in the order it's added to the pipeline.
Example configuration in Startup.cs
:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles(); // Serves static files like HTML, CSS, JS
app.UseRouting(); // Enables attribute routing and other route matching
app.UseAuthorization(); // Adds authorization to the pipeline
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
Model-View-Controller (MVC)
ASP.NET Core MVC is a popular pattern for organizing web applications:
- Model: Represents the data and business logic.
- View: The user interface, typically implemented using Razor syntax (
.cshtml
files). - Controller: Handles user input, interacts with the Model, and selects the View to render.
Razor Pages
For simpler page-based applications, Razor Pages provide an alternative to the full MVC pattern, offering a more focused approach to building Razor components.
Next Steps
This tutorial has provided a glimpse into the core concepts. To continue your journey:
- Explore building your first ASP.NET Core web application.
- Learn about data handling with Entity Framework Core.
- Understand how to create APIs with ASP.NET Core Web API.