私は自分の問題の解決策を探し回っています。同様の問題がたくさん見つかりましたが、どれも解決につながりませんでした。
エリア内にエリアを登録しようとしています。これは機能しますが、ルーティングを「部分的に」台無しにします。
登録されている順序でのルート登録。FooBar と Foo の登録は AreaRegistrations からのものであると考えてください。
routes.MapRoute("FooBar_default",
"Foo/Bar/{controller}/{action}",
new { area = "Foo/Bar", controller = "Home", action = "Index"},
new[] { BarHomeControllerType.Namespace }
);
routes.MapRoute("Foo_default",
"Foo/{controller}/{action}/{id}",
new { area = "Foo", controller = "Start", action = "Index", id = UrlParameter.Optional },
new { controller = new NotSubArea()},
new[] { typeof(StartController).Namespace }
);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("PagesRoute", "Pages/{action}", new { controller = "Pages", Action "Index" }).DataTokens["UseNamespaceFallback"] = false;
routes.MapRoute("Default", // Route name
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { typeof(HomeController).Namespace }
).DataTokens["UseNamespaceFallback"] = false;
現在、次の問題が発生しています。Website/Foo/ または Website/Foo/Bar に移動すると、これらのページのリンクは次を使用して正しく生成されます。
!{Html.ActionLink<HomeController>(c => c.Index(),"Home", new { area = "Foo/Bar"})}
or
!{ Url.Action("Index", "Home", new { area = "Foo/Bar"}) } //or a different area
ただし、これをメインページ、つまりウェブサイト/またはウェブサイト/ホームなどで使用する場合..
!{Html.ActionLink<HomeController>(c => c.Index(),"Home", new { area = ""})}
or
!{ Url.Action("Index", "Home", new { area = ""}) }
//or with no area identifier specified
Url を生成します: Website/Foo/Bar/Home など...どちらが間違っていますか。
Foo/Bar の Area 登録を削除すると、すべてが再び機能します。Website/Home/About または Website/Home の URL に直接アクセスすると、適切なページが表示されるため、内部の UrlHelper が間違ったルートを選択してレンダリングしていると思われます。
FooBar_default ルートと Foo_Default ルートの順序を入れ替えて、Foo_default ルートが FooBar_default ルートの前に登録されるようにしましたが、その領域が機能しなくなり (リソースが見つからない)、リンクが正しく生成されません。
私が最も奇妙だと思うのは、Foo/Bar 登録を削除すると問題が解決することです。私は誰かがこの問題について何らかの洞察を与えることを望んでいました..