Dav*_*ney 5 asp.net asp.net-mvc
我有一个让我疯狂的问题.
我有一个MVC 4 WebAPI应用程序,它定义了几个区域.
我的作业区发送控制器(SendController.cs)的定义如下:
namespace TargetAPI.Areas.Jobs.Controllers
{
public class SendController : ApiController
{
[HttpPost]
public HttpResponseMessage Index(SendRequest req)
{
try
{
//blah blah
}
catch (Exception ex)
{
//blah blah
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的工作区域注册(JobsAreaRegistration.cs)定义如下:
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" }
);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的RouteConfig.cs说:
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" }
);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我在其上运行路由调试器时,我得到: 我的路由调试http://imagestore2.boomerang.com/img/temp/routedebug.jpg
但当我尝试发布到"工作/发送"URL时,我得到:
未找到路径'/ Jobs/Send'的控制器或未实现IController.
我已经尝试了很多迭代和组合,我的脑袋正在旋转.有任何想法吗?
谢谢!
Dav*_*ney 10
原来WebAPI不处理区域!想象一下我的惊讶.所以我找到了一篇很棒的帖子http://blogs.infosupport.com/asp-net-mvc-4-rc-getting-webapi-and-areas-to-play-nicely/.现在我向前迈进了.
| 归档时间: |
|
| 查看次数: |
2978 次 |
| 最近记录: |