How to read AuthenticationProviderKey
, DownstreamPathTemplate
, DownstreamHostAndPorts
based on the UpstreamPath
as input?
#1987
-
My route information in the ocelot.json as {
"DownstreamPathTemplate": "/api/inbound/{RestRoute}",
"DownstreamScheme": "http"
"DownstreamHostAndPorts": [
{ "Host": "Localhost", "Port": 51712 }
],
"AuthenticationOptions":{
"AuthenticationProviderKey": "ApiKey",
"AlLowedScopes": []
},
"UpstreamPathTemplate": "/api/dev/inbound/{RestRoute}",
"UpstreamHttpMethod": [ "post","get", "Options"]
} I want to get the Could you please suggest the way that how can I get the above information when we call the upstream URL? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @pradeep1403 ! In what place/class/middleware do you need properties of the route? Anyway, route information can be found like this:
So, the 2nd dev approach gives you what you want, but you have to find required route by a predicate. It is a bit overhead coding! Just use 1st approach with concrete Hope it helps! |
Beta Was this translation helpful? Give feedback.
Hi @pradeep1403 !
Welcome to Ocelot world! 🐯
In what place/class/middleware do you need properties of the route?
Anyway, route information can be found like this:
HttpContext.Items
helpers (see HttpItemsExtensions class). So, you need to use the couple of these methods:UpsertDownstreamRoute
andDownstreamRoute
. Look into the Ocelot code and you will see tons of examples how to use these extensionsIOptions<T>
pattern to inject the config model into a constructor. The 1st example ofIOptions<FileConfiguration>
usage is here:Ocelot/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs
Line 21 in 5a3c55e
S…