# Middleware

Code that runs on every request, in order, around your endpoints.

## What is **Middleware**?

**Middleware** is code that runs on every request, in order, before and after your endpoint, like security checks at an airport. Logging, HTTPS redirection, authentication and error handling are all middleware.

```csharp
app.Use(async (context, next) =>
{
    var started = Stopwatch.GetTimestamp();
    await next(context);
    app.Logger.LogInformation("{Path} took {Ms} ms", context.Request.Path, Stopwatch.GetElapsedTime(started).TotalMilliseconds);
});
```

Level: Journeyman · [More ASP.NET Core terms at this level](https://www.ask-codey.com/glossary?category=aspnet-core&level=3)

Updated: September 27, 2026

## In other subjects

- [Middleware in Software Development](https://www.ask-codey.com/glossary/middleware-software-development)

Source: https://www.ask-codey.com/glossary/middleware-aspnet-core
