Reputation: 3678
I have created a project using ASP.NET Core Web Application (.NET Framework). My project structure:
My values controller is inherited from an MVC controller. When I hit http://localhost:20798/api/values, I do get the desired response.
I added ConsumerScore controller, this time a WebAPI controller inheriting from ApiController
. But now when I hit http://localhost:20798/api/consumerscore, I am getting 404 response.
My ConsumerScore
controller looks like:
How to resolve this error?
Upvotes: 2
Views: 2270
Reputation: 34
The error is with the "ApiController" you should use just Controller in your implementation.
There is indeed to particular ApiController class anymore since MVC and WebAPI have been merged in ASP.NET Core. However, the Controller class of MVC brings in a bunch of features you probably won't need when developing just a Web API, such as a views and model binding.
for more see: Is ApiController deprecated in .NET CORE?
Upvotes: 1
Reputation: 242
Seems like you are confusing the idea of "MVC" and "Web API".
ASP.net MVC is used for serving web pages while the Web API is supposed to be serving data in a negotiable way (json/xml/...) to http requests.
Adding an "api/*" to an MVC route and serving data from an MVC Controller
is not the best idea and will not turn it into a useful web service.
From the look of your methods, I suppose what you need is an ApiController but you cannot create the http request by copying the "~/api/*" to your web browser and you need to use tools like fiddler or your browser's debugger.
Upvotes: 0