Tôi đang gặp vấn đề khiến tôi phát điên.MVC 4 Vùng API Web 404 Lỗi
Tôi có ứng dụng MVC 4 WebAPI có một số Vùng được xác định.
My Jobs Diện tích Gởi khiển (SendController.cs) được định nghĩa như sau:
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 Diện tích đăng ký (JobsAreaRegistration.cs) được định nghĩa như sau:
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 nói:
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" }
);
}
}
}
Khi tôi chạy trình gỡ rối tuyến đường trên đó, tôi nhận được: My Route Debug http://imagestore2.boomerang.com/img/temp/routedebug.jpg
Nhưng khi tôi cố gắng để gửi đến URL "Jobs/Send" Tôi nhận được:
Bộ điều khiển cho con đường '/ Jobs/Gửi' không tìm thấy hoặc không thực hiện IController.
Tôi đã thử rất nhiều lần lặp lại và kết hợp mà đầu của tôi đang quay. Ý tưởng nào?
Cảm ơn!
Chà, thật không may. một ngày googling, và cuối cùng đã tìm thấy câu trả lời này. Cảm ơn. – Derrick