Microsoft Logo

MSDN Documentation

.NET Web Development Tutorials

Explore a comprehensive collection of tutorials designed to guide you through building robust and scalable web applications with the .NET ecosystem.

Getting Started

Advanced Topics

Featured Technologies

Example Code Snippet (ASP.NET Core Middleware)


using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

public class CustomMiddleware
{
    private readonly RequestDelegate _next;

    public CustomMiddleware(RequestDelegate next)
    {
        _next = next;
    }

    public async Task InvokeAsync(HttpContext context)
    {
        // Log request details
        context.Response.Headers.Add("X-Custom-Header", "HelloFromMiddleware");

        await _next(context); // Call the next middleware in the pipeline

        // Modify response if needed
        // context.Response.StatusCode = 200;
    }
}

// In Startup.cs or Program.cs:
// app.UseMiddleware<CustomMiddleware>();