I would like to learn how setup prefix routing like there is in cakephp for admin routing. Unfortunately I have not figured out how to do this in ASP.NET MVC.
For example,
If the user types in /Admin/Management, I would like controller Management.admin_index to be called, without changing the url. I tried what I thought was correct but it ended up changing all my urls.
So the question is: If it is possible, how do I do prefix routing in ASP.NET MVC?
Update: This is exactly what I was looking for. http://devlicio.us/blogs/billy_mccafferty/archive/2009/01/22/mvc-quot-areas-quot-as-hierarchical-subfolders-under-views.aspx This code allows you to have a default website, and then an admin area.
Maybe you should try writing a custom route. Look at System.Web.Routing.RouteBase.
* edit *
Ok, I had another look and I was wrong. What was initially my first thought turned out to be the easier solution: you should implement a custom IRouteHandler like this:
Then, make a controller with two actions, prefix one of them with ‘Admin’, and mark it with the AuthorizeAttribute. It should look something like this:
Make a ‘Prefixed’ folder in the Views folder and add two Views in it, a Test.aspx and a AdminTest.aspx. Then you just need to replace the default route (in Global.asax) with this code:
And that’s it, when you now navigate to site/Prefixed/Test as an anonymous user you should get the standard Test view, but if you are an admin you will get the AdminTest view. If an anonymous user, however, tries to access AdminTest url directly he will be sent to the login page.
PS: I can confirm this works, sou if you have problems implementing it just give me a ring 😉