The Request is Invalid Error from ASP.NET Web API

Introduction 
 
This post explains the 'The Request is Invalid' error from the ASP.NET Web API.
  
The Request Is Invalid Error From ASP.NET Web API
 
The Request Is Invalid Error From ASP.NET Web API
 
Error Reason:
  • Forgot to define routing.
  • Same method name.
Solved this error using Routing on the method level.
  1.       [HttpGet]  
  2.       public List<string> GetAllString()  
  3.       {  
  4.           return new List<string> {"ABC","XYZ" };  
  5.       }  
  6.   
  7.       [HttpGet]  
  8.       [Route("NumberList")]  
  9.       public List<int> GetAllNumbers()  
  10.       {  
  11.           return new List<int> { 122, 555 };  
  12.       }  
  13.   
  14.       [HttpGet]  
  15.       [Route("api/numberapi/NumberList")]  
  16.       public List<int> GetAllEvenNumber()  
  17.       {  
  18.           return new List<int> { 22, 44,66 };  
  19.       }  
Problem Solved
 
http://localhost:50297/numberlist
 
The Request Is Invalid Error From ASP.NET Web API
 
http://localhost:50297/api/numberapi/numberlist
 
The Request Is Invalid Error From ASP.NET Web API
 
NOTE
 
Some times the above solution will not fit or suit as per your current scenario. Please go through the following external links for solutions.
 
Other Links: