我有這個代碼這個Global.asax文件:不能在MVC找到控制器3項目 - NOTFOUND錯誤
routes.MapRoute("Invitations",
"api/invitations",
new { controller = "Invitations", action = "Invitation"});
而且我有一個控制器:
public class InvitationsController : Controller
{
[HttpPut]
public JsonResult Invitation(InvitationResponse invitationResponse)
{
//code
}
}
而且我通過HttpWebRequest使用此URL訪問控制器:
"http://localhost:6055/API/Invitations"
當我運行這個時,我得到錯誤「NotFound」。
編輯:
整個全球航線:
routes.IgnoreRoute( 「{}資源個.axd/{*} PATHINFO」);
routes.MapRoute("Users",
"api/users/{id}",
new { controller = "Users", action = "UserAction", id = UrlParameter.Optional });
routes.MapRoute("CheckIn",
"api/checkins",
new { controller = "CheckIn", action = "CheckIn" });
routes.MapRoute("Appointments",
"api/appointments/{id}",
new { controller = "Appointments", action = "Appointment", id = UrlParameter.Optional });
routes.MapRoute("UserAppointments",
"api/users/{userId}/appointments/{startDate}",
new { controller = "Appointments", action = "UserAppointments", startDate = UrlParameter.Optional });
routes.MapRoute("UserInvitations",
"api/users/{userId}/invitations",
new { controller = "Invitations", action = "UserInvitations" });
routes.MapRoute("UserOverview",
"api/users/{id}/overview",
new { controller = "Users", action = "Overview" });
routes.MapRoute("Invitations",
"api/invitations",
new { controller = "Invitations", action = "Invitation"});
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
我不知道[本測試人員](http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx)是否適用於MVC3(適用於MVC2),但你可以試試它,它是測試你的路由配置的好工具。 –
我測試了測試儀,發現它與當前請求相符 – user1156691
然後,您的路由似乎配置正確,並且您的請求應該觸發控制器/操作。它的請求是否與路由層次結構中較高的其他路由不匹配? –