0

I'm creating a web application with a web api, both will be placed in the same project.

I've already made the api work, but since they will all be in the same application, I'd like to put all my APi files, like controllers, models etc, in a separated area.

I added a new area called api, and it createad a apiAreaRegistration class with the following code:

public override void RegisterArea(AreaRegistrationContext context) 
{
   context.MapRoute(
       "api_default",
       "api/{controller}/{action}/{id}",
       new { action ="Index", id = UrlParameter.Optional }
   );
}

But the application already had the following code in WebApiConfig.cs:

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

If a create a common mvc controller in api area, i can access it throught /api/MyControlller/MyAction, but if i create a ApiController, in the api area, i get a 404 error when trying to access it.

So, my question is, how can i put my api in this separate area, and access it throught common api calls: /api/MyController/MyAction ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.