Along with built-in middleware, there are 2 options to define inline middleware using app.Use and app.Run extension methods. And if you are currently working and playing with ASP.NET Core 1.0 then you may find examples of app.Use and app.Run in configure() method of Startup.cs class. Both of them are used for same purpose but they are different. How?

app.Use vs app.Run in ASP.NET Core middleware

Middleware are executed in the same order in which they are added. The difference is, middleware defined using app.Use may call next middleware component in the pipeline. On the other hand, middlware defined using app.Run will never call subsequent middleware. Let’s see via code.

Create a new ASP.NET Core 1.0 web application and change the Startup.configure method to below code. The following example defines 2 inline middleware using app.Use and one using app.Run. The first middleware defined using app.Use writes HTML to response object asynchronously, calls next middleware and again writes closing HTML. And middleware defined using app.Run writes message and then returns. And after app.Run middlware, we defined another inline middleware using app.Use and also using some of the built-in middleware.