0

What are the best practices for setting up projects with multiple interfaces in asp.net MVC2? I'm starting a project where we need a typical arrangement like:

example.com/ - end-user interface

example.com/Admin/ - site management

The site will be involved enough that simply having all the user logic in HomeController and all the admin logic in AdminController isn't really an option. I've read about using multiple Route definitions, but the following doesn't seem to work properly:

routes.MapRoute(
            "Admin", // Route name
            "Admin/{controller}/{action}/{id}", // URL with parameters
            new { controller = "Admin", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

It causes all the links on the homepage to point to example.com/Admin/local-part instead of example.com/local-part.

I'd like to avoid specifying a different MapRoute for each Admin controller (omitting {controller} from the mapping each time).

I've also read about setting up different Areas within a project, but that seems like it would be too involved for the scope of this project.

Finally, I've also read that you can put constraints on MapRoutes, but the documentation on that part seems confusing to me. Is there something obvious I'm missing? Failing that, are there any best practices for asp.net structure that I should keep in mind?

1 Answer 1

2

It sounds like Area's is ready made for what you want to do. Setting up an area isn't really all that involved, basically you just have to register it. By default the area routing will match the default in the global.asax, the exception being the extra "\area" slug in the url. I'm fairly certain it only took me a few minutes when I set this up on a project a few months ago.

If your Admin controller is complicated enough to exceed the scope of a single controller then that indicates that an area may be warranted.

Sign up to request clarification or add additional context in comments.

Comments

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.