Skip to content

How to inject a middleware correctly having the route info? #2118

Answered by raman-m
jorge-ribeiro asked this question in Q&A
Discussion options

You must be logged in to vote

Hello Jorge!
Welcome to Ocelot world! 🐯

The thing is when I add my middleware like:

app.UseMiddleware<CaptchaPayloadMiddleware>();
app.UseOcelot().Wait();

The response is sent back nicely but i cannot access route info...

To make route information available in the HttpContext, including Route Metadata, you need to:

  • Convert the CaptchaPayloadMiddleware into an anonymous or named Func<HttpContext, Func<Task>, Task> delegate.
  • Attach the Func delegate to an OcelotPipelineConfiguration instance within the UseOcelot method, utilizing the Middleware Injection feature.

Please be aware that Ocelot utilizes a unique internal middleware signature, which differs from the classic ASP.NET middlewar…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by raman-m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Middlewares Ocelot feature: Middleware Injection Configuration Ocelot feature: Configuration Delegating Handlers Ocelot feature: Delegating Handlers Metadata Ocelot feature: Metadata
2 participants
Converted from issue

This discussion was converted from issue #2115 on July 08, 2024 15:52.