views:

48

answers:

2

I am working on a website in which many users can create their account and have a personalized page. I wish to provide them a twitter like url to access their pages, for example www.mysite.com/smith or www.mysite.com/john . I am using asp.net mvc 1.0. I have an understand that i can add routes to the global.asax file, but i am not able to figure out how to add a route that will work for such urls.

Please provide some help / suggestions. Thanks.

+2  A: 

Well, you can always add this as a last route:

routes.MapRoute(
    "Default",
    "{profile}",
    new { controller = "Profile", action = "Index" }
);

but this will make your app more cumbersome. Specifically, you'll have to check usernames so that they don't collide with the rest of your routes (like /info, '/admin' etc.).

What I recommend is to move personalization page one level deeper:

routes.MapRoute(
    "Default",
    "profile/{username}",
    new { controller = "Profile", action = "Index" }
);
Anton Gogolev
Thanks , it worked !
Bootcamp
A: 

For my part, I would use the following, placed after all other routes, but befare a catchall:

routes.MapRoute( 
    "PrettyProfile", 
    "{username}", 
    new { controller = "Profile", action = "Index" } 
); 

As Anton says, you have to constrain your userIDs not to clash with your other routes.

Fanged