MVC-应用程序根目录使用Url.Content / Url.Action在URL中出现两次 [英] MVC - Application root appears twice in url using Url.Content/Url.Action
问题描述
我在同一个域上有几个mvc应用程序,每个应用程序都有自己的目录。
I have several mvc applications on the same domain, each have their own directory.
mydomain.com/app1
mydomain.com/ app2
等。
mydomain.com/app1
mydomain.com/app2
etc..
在根级别使用Url.Content()和Url.Action()时, app1部分为在网址中重复两次。
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
我的路线-我正在使用 Phil haacks博客文章
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。
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.
-
在根目录或子目录中指定要用于路由的名称空间。 http://msdn.microsoft.com/en-us/library/dd504958。 aspx
routes.MapRoute(
Root,,new {...},
new [] { MyNamespace.For.Root}
);
routes.MapRoute( "Root", "", new {...}, new[] { "MyNamespace.For.Root" } );
或在根目录中,将子目录指定为使用的忽略路由。 http://msdn.microsoft.com/en-us/library/dd505203。 aspx
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);
条路线。IgnoreRoute( / app2);
routes.IgnoreRoute("/app1"); routes.IgnoreRoute("/app2");
这篇关于MVC-应用程序根目录使用Url.Content / Url.Action在URL中出现两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!