I want only one controller action to handle all GETs. How can I map a route to do this?
+2
A:
routes.MapRoute("AllGETs",
"{*any}",
new { Controller = "YourController", Action = "YourAction" },
new { HttpMethod = new HttpMethodConstraint("GET") }
);
eu-ge-ne
2009-08-07 19:41:08
Hmm...that doesn't seem to work. I browse to localhost:4075/NewAccount and get a Resource not Found.
Crios
2009-08-07 19:44:56
If your action has parameters (for example `string id`) add defaults to the route: `new { Controller = ..., Id = "" }`
eu-ge-ne
2009-08-07 19:47:44
And try to put this route to the top of your RouteTable
eu-ge-ne
2009-08-07 19:56:11
Don't forget that the controller value is the type name of the controller sans "Controller". So if you have "FooController" then the route should have new {Controller="Foo", Action = "ActionMethodName"}
Haacked
2009-08-07 23:39:12
A:
I actually ended up doing this, seemed to do what I needed:
routes.MapRoute( "Default", // Route name "{controller}/{id}", // URL with parameters new { controller = "Home", action = "GenericPostHandler", id = "" } // Parameter defaults );
Crios
2009-08-07 20:06:43