0

Is there a way to configure ASP.Net Core API routing based on folder structure or namespaces. Let's say I create a subfolder Documents in the Controllers folder, and then a controller WatermarksController in it. Then I want the routes to its actions to be /Documents/Watermarks/[action].

I know I can achieve this by manually applying the Route() attribute to the controller class, but is there a way to programmatically set up routes on application start, using either namespaces of file system?

Andrew
  • 1,139
  • 1
  • 12
  • 27
  • Possible duplicate of [Restrict route to controller namespace in ASP.NET Core](http://stackoverflow.com/questions/34306891/restrict-route-to-controller-namespace-in-asp-net-core) – Set Feb 24 '17 at 11:51
  • Its not exactly a duplicate, but yes you would have to replace the router with your custom router to check on namespace. Note: after code being compiled there is no notion of 'Folder' since it is all in 1 dll. So the namespaces HAVE to match the foldername – Joel Harkes Feb 24 '17 at 12:46
  • @Set Thanks for the link. That solution still requires placing attributes everywhere. Ideally I'm looking for a solution where on application start my code will find all controllers and set the routes as /[controller]/[action], were is namespace path relative to .Controllers. On a different note, I've been struggling with this problem for several months now, and also not getting any replies here: http://stackoverflow.com/questions/42357912/net-core-and-project-lock-json. Maybe you can help? – Andrew Feb 24 '17 at 22:26
  • any solution on this? – pouyada Sep 15 '20 at 13:10

0 Answers0