Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 4 Web API Areas 404 Error: "The controller for path '/Jobs/Send' was not found or does not implement IController."

I'm having an issue that is driving me nuts.

I have an MVC 4 WebAPI application that has several Areas defined.

My Jobs Area Send controller (SendController.cs) is defined like so:

namespace TargetAPI.Areas.Jobs.Controllers
{
    public class SendController : ApiController
    {
        [HttpPost]
        public HttpResponseMessage Index(SendRequest req)
        {
            try
            {
            //blah blah
            }
            catch (Exception ex)
            {
            //blah blah
            }
        }
    }
}

My Jobs Area Registration (JobsAreaRegistration.cs) is defined like so:

namespace TargetAPI.Areas.Jobs
{
    public class JobsAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "Jobs";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Jobs_long",
                "Jobs/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                new[] { "TargetAPI.Areas.Jobs.Controllers" }
            );
        }
    }
}

My RouteConfig.cs says:

namespace TargetAPI
{
    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 },
                 namespaces: new string[] { "TargetAPI.Controllers" }
            );
        }
    }
}

When I run the route debugger on it I get: My Route Debug
(source: boomerang.com)

But when I try to post to the URL "Jobs/Send" I get:

The controller for path '/Jobs/Send' was not found or does not implement IController.

I've tried so many iterations and combinations my head is spinning. Any ideas?

Thanks!

like image 897
An Old Guy and His Dog Avatar asked Sep 06 '12 00:09

An Old Guy and His Dog


1 Answers

Turns out the WebAPI does NOT handles Areas! Imagine my surprise. So I found a GREAT post http://blogs.infosupport.com/asp-net-mvc-4-rc-getting-webapi-and-areas-to-play-nicely/. Now I am moving forward.

like image 63
An Old Guy and His Dog Avatar answered Nov 15 '22 09:11

An Old Guy and His Dog