Web api: The requested resource does not support http method 'GET'

hansenbanana

New Member
I created an API controller on my MVC4 projectHere is the method I created to test the functionality of the API\[code\]private string Login(int id){ Employee emp = db.Employees.Find(id); return emp.Firstname;}\[/code\]When I try to access this api with \[code\]localhost:xxxx/api/controllerName/Login?id=2\[/code\], I get\[quote\] {"$id":"1","Message":"The requested resource does not support http method 'GET'."}\[/quote\]What am I doing wrong?Also, here is my api config file\[code\]public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var json = config.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects; config.Formatters.Remove(config.Formatters.XmlFormatter); }\[/code\]
 
Top