我有这个:
public class RuleController : ApiController
{
private readonly IRuleManager _ruleManager;
// GET: api/Rule/guid
[HttpGet]
public IHttpActionResult GetRule(Guid id)
{
var rules = _ruleManager.GetRulesById(id);
return Ok(rules);
}
[HttpGet]
public async Task<IHttpActionResult> GetRuleNew(string locale, string pno, string modelYear)
{
// do cool stuff with my params
}
}
my route config:
config.Routes.MapHttpRoute("DefaultApiWithId", "Api/{controller}/{id}", new { id = RouteParameter.Optional }, new { id = @"d+" });
config.Routes.MapHttpRoute("DefaultApiWithAction", "Api/{controller}/{action}");
config.Routes.MapHttpRoute("DefaultApiGet", "Api/{controller}", new { action = "Get" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) });
config.Routes.MapHttpRoute("DefaultApiPost", "Api/{controller}", new { action = "Post" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) });
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
调用我的路由:
https://localhost:44328/api/rule/GetRuleNew?locale=e?pno=2?modelYear=1
我:
Message": "未找到与请求URI匹配的HTTP资源"https://localhost: 44328/api/规则/GetRuleNew ?地区= e ? pno = 2 ? modelYear = 1的干净,MessageDetail": "在控制器'规则'上找不到任何操作匹配请求。">
我错过了什么?
你试过用这个代替吗?
https://localhost:44328/api/rule/GetRuleNew?locale=e&pno=2&modelYear=1
基本上只使用&
(而不是?
)作为第二个和随后的查询参数…