-1

What happens if I don't call next() method or next.Invoke() in a Use() method in the request pipeline, will it call the next middleware component or not?

James Z
  • 12,209
  • 10
  • 24
  • 44
Shivani
  • 224
  • 5
  • 19
  • Nope, the request will progress no further. Fairly useful if you want to intercept requests. – phuzi Nov 11 '19 at 16:13

1 Answers1

0

From the docs, emphasis mine:

Chain multiple request delegates together with Use. The next parameter represents the next delegate in the pipeline. You can short-circuit the pipeline by not calling the next parameter.

And:

When a delegate doesn't pass a request to the next delegate, it's called short-circuiting the request pipeline. Short-circuiting is often desirable because it avoids unnecessary work. For example, Static File Middleware can act as a terminal middleware by processing a request for a static file and short-circuiting the rest of the pipeline.

So if you don't invoke the next item, the pipeline will stop there.

DavidG
  • 113,891
  • 12
  • 217
  • 223