user96931
user96931

Reputation:

URL route Catch all

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

Upvotes: 3

Views: 269

Answers (1)

eu-ge-ne
eu-ge-ne

Reputation: 28153

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 = "" }
);

Upvotes: 1

Related Questions