我在同一域上有多个 mvc 应用程序,每个应用程序都有自己的目录。
mydomain.com/app1
mydomain.com/app2
等等..
在根级别使用 Url.Content() 和 Url.Action() 时,“app1”部分在 URL 中重复两次。
// 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 = "" }
);
有什么想法吗?
最佳答案
这是因为应用程序按照从最内层目录到最外层目录的顺序处理 web.configs。
您有两种选择来修复此行为。
指定您希望路由应用于根目录或子目录中的命名空间。 http://msdn.microsoft.com/en-us/library/dd504958.aspx
路线.MapRoute( “根”,“”,新的{...}, new[] { "MyNamespace.For.Root"} );
或者在根目录中将子目录指定为忽略的路由。 http://msdn.microsoft.com/en-us/library/dd505203.aspx
routes.IgnoreRoute("/app1"); 路线.IgnoreRoute(“/app2”);
关于asp.net-mvc - MVC - 应用程序根目录在使用 Url.Content/Url.Action 的 url 中出现两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2217697/