Tricky MVC URL Rewriting

I am working on an mvc application and I wanted to make the user’s main page (profile) be  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 {*catchall} and do my own parsing but why re-invent the wheel – plus I suck at regular expression.  What I ended up doing is registering all the routes manually.  So if I wanted to go to /message/create, I would register a route like this:

So far so good, nothing earth shattering.  So I basically did this for all my routes and the last route, I added was:

This basically will catch any route that has not been defined before it and will treat it as a username so /eibrahim would go to the view action on the user’s controller.  Also, note that I added a constraint to prevent the catch-all route from catching any url in the content subfolder.  Important: All your scripts, images, css files and so on have to be in the content folder otherwise they will be handled by the catch-all route and not be accessible to your application.

The signature for the view action look like this:

Now the tricky part is that you want to make sure that your users don’t signup with a username matching the controller.  So if a user decided to register with the username “message”, he will never be able to go to his profile at /message because it will be handled by the generic message route “message/{action}”.  A quick workaround is to prevent the user from registering with those names.  In my signup process I call a method to check if the selected username is valid.  The validation process loops through all the routes and makes sure the username doesn’t match any controller or action.  It works out pretty well so far.

I don’t know if this is the best solution, so if you know of a better way to do it, let me know.