How to get to the asp.net web api action?
I am new to web api so I am trying to catch action (action named Test) in web api controller with no success, always get. Resource is not found. Error 404
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 am getting 404 error
+3
source to share