Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWIN app.use vs app.run vs app.map

Tags:

What's the difference among app.use, app.run, app.map in Owin? When to use what? It's not straightforward when reading the documentation.

like image 800
Bad Avatar asked Feb 22 '16 17:02

Bad


People also ask

What is the difference between app use and app run?

For app. Run , it adds a terminal middleware delegate to the application's request pipeline. For app. Use , it adds a middleware delegate to the application's request pipeline.

What is the difference between IApplicationBuilder use () and IApplicationBuilder run ()?

Run() is an extension method on IApplicationBuilder instance which adds a terminal middleware to the application's request pipeline. The Run method is an extension method on IApplicationBuilder and accepts a parameter of RequestDelegate.

What is the difference between app run and app use middleware in .NET Core?

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.

What is app run () in .NET Core?

The Run Extension method is used for adding terminal middleware that means Adds a terminal middleware delegate to the application's request pipeline. This method takes two Parameters: app: The Microsoft. AspNetCore. Builder.


1 Answers

app.use inserts a middleware into the pipeline which requires you to call the next middleware by calling next.Invoke().

app.run inserts a middleware without a next, so it just runs.

With app.map you can map paths, which get evaluated at runtime, per request, to run certain middleware only if the request path matches the pattern you mapped.

See docs for use and run and map for more details

like image 149
MichaC Avatar answered Oct 22 '22 23:10

MichaC