我希望根据查询参数值处理不同的操作来处理请求。
例如:
mydomain.com/controller/action?version=1&msg=hello
和
mydomain.com/controller/action?version=2&msg=5
应根据版本值转到不同的处理程序。
查询参数列表必需/可选,以及它们的类型可能会更改 - 在version = 1中,msg是一个字符串,在version = 2中它是一个整数
答案 0 :(得分:2)
您可以使用Route Constraints:
routes.MapRoute("first", "/controller/action/{version}/{msg}",
new {controller = "controller", action = "action",
version = String.Empty, msg = String.Empty},
new {version = "1"});
routes.MapRoute("first", "/controller/action/{version}/{msg}",
new {controller = "controller", action = "action2",
version = String.Empty, msg = String.Empty},
new {version = "2"});