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
This is my controller:
public class ReadController : ApiController
{
[HttpGet]
public IHttpActionResult Test()
{
return Ok();
}
// GET: api/Read
public IEnumerable<string> 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
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/Test
in both cases I get 404 error