Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am developing, application in Wep API2,I want to use Routing at two different controller(It is working fine with only single controller in Each Method), but throughing error: 404
Please share< How I can do?
Posted

1 solution

Hi,

You can define your routing inside the RegisterRoute Method like following.

C#
public static void RegisterRoutes(HttpRouteCollection routes) {

    routes.MapHttpRoute(
        "UserRolesHttpRoute",
        "api/users/{key}/roles",
        new { controller = "UserRoles" });

    routes.MapHttpRoute(
        "AffiliateShipmentsHttpRoute",
        "api/affiliates/{key}/shipments",
        new { controller = "AffiliateShipments" });

    routes.MapHttpRoute(
        "ShipmentStatesHttpRoute",
        "api/shipments/{key}/shipmentstates",
        new { controller = "ShipmentStates" });

    routes.MapHttpRoute(
        "AffiliateShipmentShipmentStatesHttpRoute",
        "api/affiliates/{key}/shipments/{shipmentKey}/shipmentstates",
        new { controller = "AffiliateShipmentShipmentStates" });

    routes.MapHttpRoute(
        "DefaultHttpRoute",
        "api/{controller}/{key}",
        new { key = RouteParameter.Optional });
}


You can know more about web api routing on this article.

[Routing with Web API]

[Multiple Controller Routing with Web API]
Hope this will help you.
thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900