I am working on an administrative panel which, in short, provides CRUD functionality for many classes/models such as Users. The way I have this implemented now is really simple; generate controller and views using a scaffolding template, then combine them all under a top level Admin directory.
The application has expanded a lot and the admin controller now encompasses the contents of 5 other controllers. The admin view folder has 20+ views. Additionally, the paths for the admin page look horrible!
/Admin/UserCreate
/Admin/GroupCreate
...
I think I can use routing to fix this. My thoughts are that it would be possible to keep each controller separated, but still be reflected as part of the admin page:
/Admin/User/Create
/Admin/Group/Create
This would make the path easier to read and make the directory structure of this application much more bearable.
1) Is it possible to utilize custom routing to essentially make “sub-controllers”? Is there a better way? I have never worked with routes before.
2) At some point, I plan on locking the admin controller off from users via a filter on that controller. If I change the routing as above, would my security filter still function properly? Do I need to apply the same filter to each of the “sub” controller?
This is achievable using MVC Areas.
Using your above example, you would simply create a separate Admin area and put that controller/action structure within that, whilst still maintain your default area without the Admin prefix. 🙂
As for your other question, you could use the
Authorizeattribute to handle security, or implement your own (deriving fromActionFilterAttribute) and decorate your secure methods with it.