views:

41

answers:

1

Hi,

I've a very basic ASP.NET MVC application that uses the default routing. Now I need to route all the requests that comes with out a specific URL to one action with a single parameter. Examples: www.myapp.com/2374982 www.myapp.com/3242342

should be routed to the same action: public ActionResult ViewById(intid) ....

Thanks, Eden

A: 

Just define the route without {controller}/{action} part

routes.MapRoute("ById", "{id}", new { controller = "Home", action = "ViewById"}, new{id = @"\d+"});

The last parameter is constraint, which makes sure that the id is a number.

Mika Kolari
Of course I did try this trivial solution. And it doesn't work. I get 404. Did you try something like that yourself and it worked??!
Eden
I just tested it, and it works.Try commenting other route definitions and check controller/action names.
Mika Kolari
You are right it was the default routers.MapRoute that did the problem. I just had to reorder them. Thanks!
Eden