Ich habe fünf Aktionen in meinem Web-API-Controller wie folgt.web api single benutzerdefinierte Routing für alle Aktionen
http://localhost:1234/products
- getallproduct
Aktion
http://localhost:1234/products/1
zur Karte - zur Karte getproductnyid
Aktion
http://localhost:1234/products
-saveproduct
Aktion (post)
http://localhost:1234/products/1/getcolor
-getproductcolorbyid
Aktion
http://localhost:1234/products/1/getcost
-getproductcostbyid
Aktion
Ich brauche nur eine benutzerdefinierte Routing-URL dafür.
Ich habe folgenden Routing versucht, aber es hängt Action Name in URL (http://localhost:24007/product/GetProductByID/Id
), die ich nicht will.
config.Routes.MapHttpRoute(
name: "ProductRoute",
routeTemplate: "product/{action}/{productId}",
defaults: new { controller = "Product", productId= RouteParameter.Optional }
);
Dank. Gemäß der Anforderung sollten wir nicht Attribut-Routing verwenden –
Ich fürchte, Sie haben dann keine anderen Optionen. –
Können Sie bitte erklären, warum URLs wie getcolors, getcost nicht verwenden sollten? –