Asp.net mvc 4 正在routes.maproute中设置url参数的查找值

Asp.net mvc 4 正在routes.maproute中设置url参数的查找值,asp.net-mvc-4,asp.net-mvc-routing,maproute,Asp.net Mvc 4,Asp.net Mvc Routing,Maproute,是否有一种简单的方法来定义route.maproute中的查找值 示例路线: routes.MapRoute( name: "example route", url: "product/{subcat}", defaults: new { controller = "Redirect", action = "ProcessPage"} ); 其中:{subcat}只能是以下值:subcat1、sub

是否有一种简单的方法来定义route.maproute中的查找值

示例路线:

 routes.MapRoute(
              name: "example route", 
               url: "product/{subcat}", 
          defaults: new { controller = "Redirect", action = "ProcessPage"}
      );
其中:{subcat}只能是以下值:subcat1、subcat2、subcat3


我正在尝试将重定向从旧站点写入新站点(无法使用IIS),旧站点没有一致的URL,其中一些属于我的新站点的模式。我希望避免为每个重定向编写路由

可以使用正则表达式约束管线值:

routes.MapRoute(
    name: "example route", 
    url: "product/{subcat}", 
    defaults: new { controller = "Redirect", action = "ProcessPage"},
    constraints: new { subcat = @"^subcat\d*$ }
);
这里我假设约束是“subcat”加上一个整数(这是我能从您的问题中提取的最佳值)——修改它以满足您的需求。如果需要一组显式的值,只需在接受字符串列表中使用正则表达式或运算符即可:

@"^subcat1|subcat2|subcat3$"

博客会帮你的。确切的字符串列表是我一直在寻找的。非常感谢你!