产品的传入 url 将是 mydomain.com/someproductname.html 我需要限制一条路线,以便它只处理这样的 url。也使检查大小写不敏感。如果我不强制执行这样的限制,那么下面的路由也会获取 URL 请求,例如 mydomain.com/level1category/ 等,这些请求应该由不同的路由处理。
我要限制的路线(需要限制“ItemName”段):
routes.MapRoute(
"ProductLink4", // Route name
"{RootPointer}/{L1Cat}/{L2Cat}/{ItemName}", // URL with parameters
new
{
controller = "Store",
action = "ViewProduct",
},
new { controller = "Store", action = "ViewProduct" ItemName = @"[^\\s]+(\\.(?i)(html))" });
routes.MapRoute(
"ProductLink3", // Route name
"{RootPointer}/{L1Cat}/{ItemName}", // URL with parameters
new
{
controller = "Store",
action = "ViewProduct",
},
new { controller = "Store", action = "ViewProduct" });
routes.MapRoute(
"ProductLink2", // Route name
"{RootPointer}/{ItemName}", // URL with parameters
new
{
controller = "Store",
action = "ViewProduct",
},
new { controller = "Store", action = "ViewProduct" });
}