我有这个:
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
}
}
我的路由配置:
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
我得到:
"消息":"未找到与请求URI 'https://localhost:44328/api/rule/GetRuleNew?locale=e?pno=2?modelYear=1'匹配的HTTP资源。","消息详细信息":"在控制器"规则"上找不到与请求匹配的操作。"
我错过了什么?
1条答案
按热度按时间rryofs0p1#
你试过用这个代替吗?
基本上,只需对第二个和后续查询参数使用
&
(而不是?
)...