I have the following routes specified – MyHttpMethodConstraint is one that checks the HTTP Method overriden by form a variable.
routes.MapRoute("Retrieve", "{controller}/{id}/{action}", new { action = "retrieve" }, new { action = "create|retrieve|update|delete", httpMethod = new MyHttpMethodConstraint("GET", "HEAD"), id = new GuidRouteConstraint() });
routes.MapRoute("Update", "{controller}/{id}", new { action = "update" }, new { action = "update", httpMethod = new MyHttpMethodConstraint("PUT"), id = new GuidRouteConstraint() });
routes.MapRoute("Delete", "{controller}/{id}", new { action = "destroy" }, new { action = "delete", httpMethod = new MyHttpMethodConstraint("DELETE"), id = new GuidRouteConstraint() });
routes.MapRoute("Create", "{controller}", new { action = "create" }, new { action = "create", httpMethod = new MyHttpMethodConstraint("POST") });
Everthing is routed correctly incoming to the Actions, however URL generation for Url.ActionLink’s do not work as I hoped (using the routes that are constrained to HTTP GET methods) but instead finding the ones that are constrained to POST/PUT/DELETE and thus the wrong URLs. I have tried re-ordering the routes but this does not help. I expect that that URL-generation ignores the constraints.
Is there a workaround, apart from building my own ActionLink method?
EDIT
There is also a default route at the bottom of the list:
routes.MapRoute("Default", "{controller}/{action}", new { controller = "home", action = "index" });
Problem solved – the issue was that it wasn’t working for a link to the create action (i.e. when a GET) because it was not using any of the above routes, but the default route at the bottom (which doesn’t have any constraints). My list of routes (including the default one) that work are: