我正在为一些非常基本的事情而挣扎。我正试图从我的WebApi2 restful服务中得到响应,但我做不到。
我没有编辑默认的WebApi(
WebApiConfig.cs
)路线。
public class AboutController
{
[Route("api/about/{id:int}/{service1}/{service2}")]
public async Task<IHttpActionResult> Get(int accountId, string mainservice, string secondaryservice)
{
//logic
}
}
如果我(在浏览器中)导航到
http://localhost:58090/api/about
The requested resource does not support http method 'GET'.
我想这是有道理的,因为它与路线(路径)不匹配。
如果我更新与签名匹配的路径,例如
http://localhost:58090/api/about/1/a/b
No action was found on the controller About' that matches the request.
即使我加上
[HttpGet]
到
controller
,这没什么区别。
public class AboutController
{
public async Task<IHttpActionResult> Get()
{
//logic
}
}
它做了人们期望的事情。我不明白为什么添加参数会让事情变得如此混乱。
我不知道我做错了什么