0

Using ASP.NET MVC4 Routing:

If I'd like to setup a Default routing configuration for the main section of the site:

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

Then another routing configuration, something similiar to the following:

        routes.MapRoute(
            name: "FOO",
            url: "FOO/{controller}/{action}/{id}",
            defaults: new { controller = "FOO", action = "bar", id = UrlParameter.Optional }
        );

Notice the string "FOO/" in the url (just before the /{controller...

For example, I'd like to be able to access the main section of my site using a url like the following

http://dummyurl.com/bar/1

but then access controllers and actions that have identical names if I was to use

http://dummyurl.com/**FOO**/bar/1

2 Answers 2

1
routes.MapRoute(
    name: "FOO",
    url: "FOO/{controller}/{action}/{id}",
    defaults: new { controller = "FOO", action = "bar", id = UrlParameter.Optional }
);

That route will result into something that you might not expect, unless you have an mvc area named FOO. That route will only work with http://yourdomain/foo/foo/any_method_in_foo/id

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

1 Comment

Areas is without question the better solution.
1

Figured out by going through routing documentation by "the Gu" that I simply needed to put:

    routes.MapRoute(
        name: "FOO",
        url: "FOO/{controller}/{action}/{id}",
        defaults: new { controller = "FOO", action = "bar", id = UrlParameter.Optional }
    );

Above:

     routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );

in my Routes.config and blammo, good to go. I can now separate and access for example an Admin ("FOO") section in my project.

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.