.NET & C# ยท ASP.NET Core
How should middleware pipeline be used in production?
Place global exception handling early, then security and routing-related middleware in the order required by the application, with endpoint execution near the end.