Asp.net mvc 如何在MVC3中为除一个特殊URL之外的所有URL运行自定义路由
我已经为一些URL做了一些URL路由Asp.net mvc 如何在MVC3中为除一个特殊URL之外的所有URL运行自定义路由,asp.net-mvc,asp.net-mvc-3,model-view-controller,Asp.net Mvc,Asp.net Mvc 3,Model View Controller,我已经为一些URL做了一些URL路由 routes.MapRoute( "ProductDetails", "Product/{name}/{*other}", new { controller = "Product", action = "Details" } ); 上述代码将把/Product/{name}类型的所有URL路由到/Product/Details/{para
routes.MapRoute(
"ProductDetails",
"Product/{name}/{*other}",
new { controller = "Product", action = "Details" }
);
上述代码将把/Product/{name}
类型的所有URL路由到/Product/Details/{parameter}
。它工作正常,现在我想如果我输入url/Product/List
,这必须通过默认路由处理
我不想为列表再创建一条路由
请告知。为
名称
参数添加约束(不等于列表):
此路由与/Product/List
url不匹配
如果您还想排除其他名称,请更新:
^(?!(List | Foo | Bar)$).$
如何在此中添加更多约束,例如列表、编辑、创建等?如果我只想拥有与主要问题相反的其中一项,该怎么办?
routes.MapRoute(
name: "ProductDetails",
url: "Product/{name}/{*other}",
defaults: new { controller = "Product", action = "Details" },
constraints: new { name = "^(?!List$).*$" }
);