I've been struggling with this problem for at least 4 hours now, trying every solution I could find.
My main project is set up with Asp.Net and MVC which works great routing to controllers within the project. I'm integrating a library that exposes a JSON api that uses ApiControllers in another project but I can't get the main project to route to anything in the library project, it just returns a strait 404.
In my main project global.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{*allaxd}", new { allaxd = @".*\.axd(/.*)?" });
routes.IgnoreRoute("{*less}", new { less = @".*\.less(/.*)?" });
//ignore aspx pages (web forms take care of these)
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.IgnoreRoute("{resource}.css/{*pathInfo}");
//ControllerBuilder.Current.DefaultNamespaces.Add("Nexus.Controllers");
routes.MapRoute(
"testapi",
"testapi/{controller}/{action}",
new
{
controller = "User",
action = "Get"
},
new[] { "Nexus.Controllers" }
);
routes.MapRoute(
// Route name
"Default",
// URL with parameters
"{controller}/{action}/{id}",
// Parameter defaults
new { controller = "Events", action = "Index", id = "" }
);
}
In my library project UserController:
namespace Nexus.Controllers
{
public class UserController : ApiController
{
public Object Get(string id)
{
var guid = new Guid(id);
var user = crm.Users.Where(x => x.UserId == guid).FirstOrDefault();
return new
{
id = user.UserId,
name = user.UserName,
email = user.Email,
extension = user.Ext,
phone = user.Phone
};
}
}
}
None of the URLs that I expect to work do: /testapi /testapi/User /testapi/User/Get /testapi/User/Get?id=1
They all return 404.
I've even used the route debugger to verify that the routes appear to be set up correctly:
What am I missing?