views:

70

answers:

2

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
Hmm...that doesn't seem to work. I browse to localhost:4075/NewAccount and get a Resource not Found.
Crios
If your action has parameters (for example `string id`) add defaults to the route: `new { Controller = ..., Id = "" }`
eu-ge-ne
And try to put this route to the top of your RouteTable
eu-ge-ne
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
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