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?

4
  • Possible duplicate of Restrict route to controller namespace in ASP.NET Core Commented Feb 24, 2017 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 Commented Feb 24, 2017 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 <relative_namespace>/[controller]/[action], were <relative_namespace> is namespace path relative to <root_namespace>.Controllers. On a different note, I've been struggling with this problem for several months now, and also not getting any replies here: stackoverflow.com/questions/42357912/…. Maybe you can help? Commented Feb 24, 2017 at 22:26
  • any solution on this? Commented Sep 15, 2020 at 13:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.