1

I have an application and I have moved my admin panel to areas, since then I am unable to hit the adminpanel api calls. here is the code for main api registration and admin panel api registration.

    //Api registration
    public static void Register(HttpConfiguration config)
    {

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


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


    //Area Registration
    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_panel",
            "AdminPanel/{controller}/{action}/{id}",
            new { controller = "Admin", action = "Index", id = UrlParameter.Optional }
        );


        context.Routes.MapHttpRoute(
          "Admin_Secondary",
          "AdminPanel/api/{controller}/{id}",
          new { id = RouteParameter.Optional }
      );
    }

I am trying to hit it with URL localhost/taw/adminpanel/api/SearchAPI but it doesn't work. what's wrong with my routing?

1 Answer 1

7

I found out the issue, precedence of routes was creating the problem, I think I should have asked the duck before posting the issue.

      context.Routes.MapHttpRoute(
       "Admin_Secondary",
       "AdminPanel/api/{controller}/{id}",
       new { id = RouteParameter.Optional }
      );

has to come before

    context.MapRoute(
        "Admin_panel",
        "AdminPanel/{controller}/{action}/{id}",
        new { controller = "Admin", action = "Index", id = UrlParameter.Optional }
    );

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.