I know there's another thread about WebapiConfig.cs and RouteConfig.cs, but I can assure this is a different question.
My MVC project was quite developed by the time I found out I would have to create a webservice (in the same domain) where I would grant access to one of my models (both in JSON and XML).
In order to do so, I right clicked over my Controllers and selected "add Web API 2 Controller with actions, using Entity Framework" and selected also my model class and db context.
The template was quite complete and I thought I was ready to go for the following test:
namespace MVC4GMAPS.Controllers
{
public class RestController : ApiController
{
private LocationDBContext db = new LocationDBContext();
// GET api/Rest
public IQueryable<Location> GetLocations()
{
return db.Locations;
}
etc...
Unfortunately, when I tried to access to https://localhost:44300/api/Rest I've got a 404. However, localhost:44300/Home/Index keeps working great.
I believe the problem relies on my RouteConfig.cs, because it is expecting an {action} and my RestController doesn't have any actions:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
etc...
What can I do? Can I create simultaneously a WebapiConfig.cs file? I believe not. I hope you can help me!