如何使用单个路由根据参数名称调用不同的不同动作。
我需要关注
/api/v1/user
GET
key=dfddg&secret=fafassaf&query=select id from user where user like '%ggg%'
和
/api/v1/user
GET
key=dfddg&secret=fafassaf&ids=fadfdafdsf,faffasfasfsf,asfasfasfasfas,asfasfasfasf
我写了以下代码
[RoutePrefix("api/v1/user")]
public class UserController : ApiController
{
[GET("")]
public String GetAllUsers(String key, String secret, String query)
{
return "GetAllUsers";
}
[GET("")]
public String GetLookupUserIds(String key, String secret, String ids)
{
return "GetLookupUserIds";
}
但第一种情况工作正常,但第二种情况抛出异常
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:14823/api/v1/user?key=rhdgsdgdsr&secret=fhdgdgdfhdfh&ids=fdfdf,dfadfff'.",
"MessageDetail": "No action was found on the controller 'User' that matches the request."
}