【发布时间】:2021-12-12 13:51:30
【问题描述】:
我正在尝试将我的 UI 项目和 WebAPI 项目合二为一,以使其更易于维护,但是我收到以下路由错误:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:64182/api/v1/business?id=101'.",
"MessageDetail": "No type was found that matches the controller named 'api'."
}
我已在方法上添加了属性路由以使其工作,但它仅适用于以下 url:
MVC 动作:
[HttpGet, Route("api/v1/business/{id:int}")]
public IHttpActionResult Get([FromUri]int? id)
{
....
}
http://localhost:64182/api/v1/business/101
预期的 url 签名不能更改,它仍应使用查询参数:
http://localhost:64182/api/v1/business?id=101
在 Route 属性中,我不能添加问号,因为它是不允许的。
该系统已被许多用户使用,很遗憾我无法更改签名,否则会破坏他们的系统。
我怎样才能让它工作,或者我可以使用什么路由模板来包含查询参数?
【问题讨论】:
标签: c# asp.net-mvc asp.net-core asp.net-web-api routes