Overview
Server‑side development in .NET focuses on processing HTTP requests, generating responses, and managing application state. Modern .NET uses the ASP.NET Core
framework, which provides a lightweight, modular, and high‑performance stack.
Request Handling
Every HTTP request is represented by an HttpContext
instance. The context contains the request, response, user, and routing data.
public async Task InvokeAsync(HttpContext context)
{
// Custom logic before the next component
await _next(context);
// Custom logic after the next component
}
Middleware Pipeline
Middleware components are assembled in Startup.Configure
to form a request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
Component | Purpose |
---|---|
UseHttpsRedirection | Redirect HTTP to HTTPS |
UseStaticFiles | Serve files from wwwroot |
UseRouting | Match request to endpoints |
UseAuthentication | Validate user identity |
UseAuthorization | Enforce policy‑based access |
ASP.NET Core Basics
ASP.NET Core projects are built around Program.cs
and Startup.cs
. The minimal‑API style reduces boilerplate.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
app.Run();
Security Best Practices
- Enforce HTTPS with
UseHttpsRedirection
and HSTS. - Validate input using model binding and data annotations.
- Implement authentication with JWT or Identity.
- Use anti‑forgery tokens for state‑changing actions.
Deployment Options
.NET apps can be deployed to:
- Azure App Service
- Docker containers
- Self‑hosted Windows/Linux servers
- Serverless with Azure Functions
Sample Projects
Explore the official GitHub repository for ready‑to‑run examples.
dotnet/aspnetcore