1
votes

I have this global.asax file with this code:

routes.MapRoute("Invitations", 
                        "api/invitations", 
                        new { controller = "Invitations", action = "Invitation"});

And I have a Controller:

public class InvitationsController : Controller
{
    [HttpPut]
    public JsonResult Invitation(InvitationResponse invitationResponse)
    {
        //code
    }
}

And I'm accessing the controllers by HttpWebRequest with this URL:

"http://localhost:6055/API/Invitations"

When I run this I get the error "NotFound".

EDIT:

The whole global route:

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
        );
1
I don't know if this tester works on MVC3 (it works on MVC2) but you can try it, it's a great tool for testing your route configuration.Gabe Thorns
I tested the tester and i get that it mathes the current requestuser1156691
Then your routes seem to be configured correctly, and your request should hit the controller/action. It the request not matching any other route that is higher in the route hierarchy?Gabe Thorns
Those routes is all im using. Do you see any route that is higher in the hierarchy?user1156691
MVC matches the requests with the routes in order, so for instance if you place a general route (like "Default") before (that is, place the code at the top of the route configuration). MVC will match that first. The questions was if, in the tester, your "/API/Invitations" is not matching other route that comes before your "Invitations" route?Gabe Thorns

1 Answers

0
votes

"http://localhost:6055/API/Invitations" doesn't look correct, shouldn't it be

"http://localhost:6055/YourApp/API/Invitations"