如何使用regex限制路由以转到“联系”页面。如下所示
routes.MapRoute(
"Default22",
"{name}",
new
{ controller = "Home", action = "Contact" },
new { name = "Contact" });
routes.MapRoute(
"RootUrlWithAction",
"Home",
new
{
controller = "Home",
action = "Index",
name = "home",
id = UrlParameter.Optional
}
);
routes.MapRoute("root9",
"{controller}/{action}/{footer}",
new { controller = "FooterMenu", action = "Index" },
new { id = @"\d+" });
routes.MapRoute("root8",
"{controller}/{action}/{header}",
new { controller = "HeaderMenu", action = "Index" },
new { id = @"\d+" });
routes.MapRoute("root7",
"{controller}/{action}/{id}",
new { controller = "Admin", action = "Index" },
new { id = @"\d+" });
routes.MapRoute(
"Default1",
"{name}",
new
{
controller = "Home",
action = "Page"
}
);
routes.MapRoute(
"Default",
"{controller}/{action}/{name}",
new
{
controller = "Home",
action = "Index",
name = UrlParameter.Optional
}
);
routes.MapRoute(
"Default22", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}