作者:沙胆建筑_829 | 来源:互联网 | 2023-01-28 23:37
Imnewtowebapi,soItryingtocatchaction(actionwithnameTest)inwebapicontrollerwithn
I'm new to web api, so I trying to catch action (action with name Test) in web api controller with no success, always get The resource cannot be found. 404 error
我是web api新手,所以我尝试在web api控制器中捕获操作(带有名称测试的操作),但没有成功,总是无法找到资源。404错误
This is my controller:
这是我的控制器:
public class ReadController : ApiController
{
[HttpGet]
public IHttpActionResult Test()
{
return Ok();
}
// GET: api/Read
public IEnumerable Get()
{
return new string[] { "value1", "value2" };
}
// GET: api/Read/5
public string Get(int id)
{
return "value";
}
// POST: api/Read
public void Post([FromBody]string value)
{
}
// PUT: api/Read/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE: api/Read/5
public void Delete(int id)
{
}
This is my WebApiConfig class
这是我的WebApiConfig类
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Trying with this call
尝试用这个电话
https://localhost:44300/api/Read/Test
https://localhost:44300 / api /读/测试
https://localhost:44300/api/Test
https://localhost:44300 / api /测试
in both cases I get 404 error
在这两种情况下,我都会得到404错误
1 个解决方案