tags:

views:

44

answers:

1

Hi, I wondering if there is anyway to achieve a url like http://www.mycompany.com/user in MVC I tried using the catch all but could not get the user passed so I can do the look up.

Thanks

A: 

Something like this?

routes.MapRoute("User",
    "{UserName}",
    new { Controller = "User", Action = "Index", UserName = "" });

UPDATED:

add this constraint to the "User" route:

routes.MapRoute("User",
    "{UserName}",
    new { Controller = "User", Action = "Index", UserName = "" },
    new { UserName = @"(\w|-)+" }
);

or add this route:

routes.MapRoute("Home",
    String.Empty,
    new { Controller = "Home", Action = "Index", Id = "" }
);
eu-ge-ne
Just tried it, now "using localhost" now requests for the default route "http://localhost/MVCApp/" are redirected to User Controller with empty string for the UserName
Sammy
You beat me to the Constraint solution.Thank you very much
Sammy
You're welcome :)
eu-ge-ne