Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
The Request is Invalid Error from ASP.NET Web API
WhatsApp
Manoj Kalla
5y
21.5
k
0
0
25
Blog
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:
asp-net-webapi-newly-registered-route-says-that-request-is-invalid
overload-web-api-action-method-based-on-parameter-type
webapi-angularjs-the-request-is-invalid-error
web-api-request-invalid
ASP.NET
ASP.NET Web API
Request Is Invalid Error From ASP.NET Web API
Web API
Up Next
ASP.NET MVC Angular CRUD Operation Using WEB API 2 With Stored Procedure
Ebook Download
View all
Diving Into ASP.NET WebAPI
Read by 21.4k people
Download Now!
Learn
View all
Membership not found