views:

368

answers:

1

I have several mvc applications on the same domain, each have their own directory.

mydomain.com/app1
mydomain.com/app2
etc..

When using Url.Content() and Url.Action() when at the root level, 'app1' part is repeated twice in the urls.

// code used to generate the links
<%= Url.Action("tetris", "Apps") %>
Page Url:               mydomain.com/app1/
rendered link (broken): mydomain.com/app1/app1/Apps.aspx/tetris

application root appears twice in the rendered url when at the root directory
Page Url:               mydomain.com/app1/home.aspx/
rendered link (works):  mydomain.com/app1/Apps.aspx/tetris

application root appears once - everything works as expected 

my routes - I'm using the routes from Phil haacks blog post

routes.MapRoute(
    "Default",
    "{controller}.aspx/{action}/{id}",
    new { action = "Index", id = "" }
);

routes.MapRoute(
    "Root",
    "",
    new { controller = "Home", action = "Index", id = "" }
);

Any ideas?

A: 

That is because applications process web.configs in order of inner most director to outer most directory.

You have two options to fix this behavior.

  1. Specify the namespaces you want the routes to apply to either in the root directory or your sub-directories. http://msdn.microsoft.com/en-us/library/dd504958.aspx

    routes.MapRoute( "Root", "", new {...}, new[] { "MyNamespace.For.Root" } );

  2. Or in the root directory specify your sub-directories as ignored routes using. http://msdn.microsoft.com/en-us/library/dd505203.aspx

    routes.IgnoreRoute("/app1"); routes.IgnoreRoute("/app2");

Nick Berardi
1. I don't understand this, there is only one namespace, and one place to define routes, global.asax.cs. Could you eleborate on this?2. routes.IgnoreRoute("/app1") throws an exception: routeUrl cannot start with '~' or '/'.
sieben
You are having problems because your root Global.asax file is processing the URL's for your sub-apps. This is what you need to prevent. You have been very vague in your question about if the sub-applications are actual virtual applications in IIS or if they are just parts of one application hosted at the root. Does your "app1" for instance have its own Global.asax and Web.config?
Nick Berardi