What is the difference between app.Run() and app.Use() in ASP.NET Core?

app.Use() is used to register middleware that can process the request and optionally pass control to the next middleware using await next(). It’s ideal for tasks like logging, exception handling, or authentication.

app.Run() is a terminal middleware that doesn’t call next(). Once it's executed, the request ends there. I typically use app.Run() for things like a default fallback endpoint or debugging purposes.

Order matters a lot in middleware — anything registered after app.Run() won’t run. Means app.Use execute first if we add app.Use after app.Run then it will not we executed.  

Comments

Popular posts from this blog

How to design a loosely coupled system using Entity Framework, while also managing performance and memory usage effectively?

What is the difference between .NET Framework and .NET Core?

What are the main OOP Concepts in C#?