Introduction
This post explains the 'The Request is Invalid' error from the ASP.NET Web API.
Error Reason:
- Forgot to define routing.
- Same method name.
Solved this error using Routing on the method level.
- [HttpGet]
- public List<string> GetAllString()
- {
- return new List<string> {"ABC","XYZ" };
- }
-
- [HttpGet]
- [Route("NumberList")]
- public List<int> GetAllNumbers()
- {
- return new List<int> { 122, 555 };
- }
-
- [HttpGet]
- [Route("api/numberapi/NumberList")]
- public List<int> GetAllEvenNumber()
- {
- return new List<int> { 22, 44,66 };
- }
Problem Solved
http://localhost:50297/numberlist
http://localhost:50297/api/numberapi/numberlist
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: