I have an authenticate function in my company controller
[ActionName("Authenticate")]
[HttpGet]
public bool Authenticate(Company company)
{
if (Uow.Companies.AuthenticateCompany(company))
return true;
return false;
}
that is called using the following ajax query
$.ajax({ url: "/api/company/Authenticate", type: 'get', data: company })
company is a js object
Company: function (name, phoneNumber, password) {
this.Name = name;
this.PhoneNumber = phoneNumber;
this.password = password;
}
var company = new Company($('#TextBoxCompanyName').val(),'00000000', $('#TextBoxCompanyPassword').val());
and my api route is as follows
config.Routes.MapHttpRoute(
name: "Action",
routeTemplate: "api/{controller}/{action}"
);
When the code runs the web api calls the following function in the company controller
public Company Get(int id)
{
return Uow.Companies.GetById(id);
}
How do I call a custom get function?
Web.API tries to match the routes in the definition order.
From Web API Routing and Actions/Routing and Action Selection
So the order of definition of the routes matter.
You need to put your
"Action"before the"DefaultApi"Otherwise the wep.api interprets your url
/api/company/Authenticateas controller=company and id=Authenticate so it routes to your Get action.