views:

36

answers:

2

I'm looking to do something similar to this post:

http://stackoverflow.com/questions/380221/how-to-hide-controller-name-in-url

only without any sort of ID.

The server is running IIS 6 and the pages already show up without extensions so it's not a wildcard issue.

I'm looking to hit http://website.com/action-name

I have http://website.com/controller/action-name working

I'm assuming this is just a simple routing change that I am somehow goofing up. My current routing rule is:

routes.MapRoute(
    "RouteName",
"{action}",
new { controller = "Home", action = "Index" }
);
+2  A: 

The problem is your default route is still probably in place so it is matching it first and defaulting the rest of the inputs it expects. Based on your comment that the controller/action is working makes me think you didn't remove it or it is appearing first. Can you post your entire RegisterRoutes?

Try making the route you defined the very first route and it should match almost anything you pass at it.

EDIT: Added what your RegisterRoutes should look like:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    // This will match anything so if you have something very specific with hard coded
    // values or more items that will need to be match add them here above but do not
    // add defaulted values so it can still fall through to this.
    routes.MapRoute( 
        "RouteName", 
        "{action}", 
        new { controller = "Home", action = "Index" });
}
Kelsey
That was the problem as was pointed out by @Robert Harvey above.
mwright
@mwright didn't notice his answer since it was a comment and I was typing it out and trying to recreate a code scenario. I guess you don't need the code scenario anymore :)
Kelsey
Yeah, thanks for the effort
mwright
@mwright added the code anyways with some comments to explain :)
Kelsey
+2  A: 

Is your new routing rule positioned above the default routing rule of {controller, action, id} so that it has the opportunity to match first?

Robert Harvey