❔ Controller routing with dynamic parameter
Hi all guys!
That's my first post so I don't know if I'm doing anything wrong, in case let me know!
I have an api project with a lot of api that are gonna be used for both a website (control panel) and a mobile app (for customers). My controllers are all like this:
that means that my url looks like this: https://localhost:5000/api/v1/Agent
What I need is to specify in the url if that api will be used in app or web, so that my url will look like this: https://localhost:5000/api/web/v1/Agent
That parameter has to be specified for every api just like [HttpGet("GetAgentById")].
I obviously searched on web but I haven't found anything 😦
Thanks a lot ❤️
5 Replies
Why not create 2 controllers, one for the web and one for mobile? Is there a reason you want to put everything in one generic controller?
I already have all the api there, that's a solution, but I was just curious about the existence of that option!
Can't you just look at the HttpContext.Request.Headers['User-Agent'] to see if the request is from mobile or pc? You can do a custom attribute to check that and redirect.
That's not the point, my boss just wants to know if an api is for web or app reading its url 🤷♀️
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.