DISQUS

DISQUS Hello! Emad Ibrahim is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Tricky Asp.net MVC URL Rewriting

Started by eibrahim · 10 months ago

I am working on an asp.net mvc application and I wanted to make the user’s main page (profile) be www.domain.com/username.  This is a problem because the routing engine in MVC treats the first item after the domain as a controller.  Ofcourse I could do a {*cat ... Continue reading »

7 comments

  • I've done exactly this for a project. It isnt ideal in that if you have a live system, and you subsequently need to add controllers, you need to check that *existing* users havent already used that controller name.
  • hello,

    how i can route to main page without using MVC (We are using System.Web.Routing assembly)
  • @Nik, you are absolutely right which is why I force user names to be 4 characters or longer. This way, worst-case-scenario, I can create a 3 letter controller. Not ideal, but a workaround.
  • @Net framework programmer, I am not sure how to do that. I haven't used the routing library with non-MVC projects. Good luck and let us know what you find out.
  • @Net framework programmer,
    Read this http://chriscavanagh.wordpress.com/2008/03/11/a... for routing with Web Forms
  • Have you thought about what happens if you decide to create a controller which happens to be the same as a user's name?!

    I'm not sure this is a very future-proof way of working...
  • You are absolutely right but I have worked around that by forcing users to
    use usernames with 6 or more characters and I also keep track of a list of
    banned usernames in the config file e.g. administrator, account, etc...
    It is not perfect but it works otherwise, you will be stuck with URLs that
    look like /user/eibrahim instead of just /eibrahim

Add New Comment

Returning? Login