我设置了以下路线
app.UseMvc(routes =>
{
routes.MapRoute(
name: "admin",
template: "{controller=Home}/{action=Index}/{id?}",
defaults: new {Area = "Admin"},
constraints: new {HostConstraint = new MyConstraint()});
routes.MapRoute(
name: "admin-rep",
template: "Rep/{controller=Home}/{action=Index}/{id?}",
defaults: new { Area = "" },
constraints: new { HostConstraint = new MyConstraint() });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
在这种情况下,MyConstraint始终返回 true 。
<a asp-action="Action">Action</a>
@Html.ActionLink("Action", "Action")
答案 0 :(得分:3)
重新排序您的路线,先写admin-rep
然后再写admin
app.UseMvc(routes =>
{
routes.MapRoute(
name: "admin-rep",
template: "Rep/{controller=Home}/{action=Index}/{id?}",
defaults: new { Area = "" },
constraints: new { HostConstraint = new MyConstraint() });
routes.MapRoute(
name: "admin",
template: "{controller=Home}/{action=Index}/{id?}",
defaults: new {Area = "Admin"},
constraints: new {HostConstraint = new MyConstraint()});
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
答案 1 :(得分:1)
您使用了Area
,但我认为您没有在标记帮助器中指定asp-area
属性,这会导致此问题。有关设置asp-area
的更多信息,请参阅以下链接: