1

我有这个带有以下代码的 global.asax 文件:

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("{resource}.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
        );
4

1 回答 1

0

“http://localhost:6055/API/Invitations”看起来不正确,不是吗?

“http://localhost:6055/ YourApp /API/Invitations”

于 2012-11-13T12:17:09.477 回答