MVC - 应用程序根目录在使用 Url.Content/Url.Action 的 url 中出现两次
我在同一个域上有几个 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
我的路线 - 我正在使用 Phil haacks 博客文章
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为应用程序按照从最内层目录到最外层目录的顺序处理 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");
paths.IgnoreRoute("/app2");
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.
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" }
);
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");
当我遇到这个问题时,这是因为有人在控制器上使用了
RouteArea["app1"]
属性,但也将其包含在操作GET["apps1/Detail"]
中只是GET["Detail"]
When I had this issue it was because someone used
RouteArea["app1"]
attribute on the Controller but also included it on the actionGET["apps1/Detail"]
instead of justGET["Detail"]