title: ASP.NET MVC 4 route username / action issue
body: <p>I am currently working on an asp.net mvc 4 application and I have the need for the following type of urls:</p>
  
  <p><strong>Urls that need to be routed</strong></p>
  
  <blockquote>
    <ol>
    <li><a href="http://www.mysite.com/foo/user1">http://www.mysite.com/foo/user1</a>     &lt;------- {username}</li>
    <li><a href="http://www.mysite.com/foo/edit">http://www.mysite.com/foo/edit</a></li>
    <li><a href="http://www.mysite.com/foo/delete/1">http://www.mysite.com/foo/delete/1</a></li>
    <li><a href="http://www.mysite.com/bar/user1">http://www.mysite.com/bar/user1</a>     &lt;------- {username} </li>
    <li><a href="http://www.mysite.com/bar/edit">http://www.mysite.com/bar/edit</a></li>
    <li><a href="http://www.mysite.com/bar/delete/1">http://www.mysite.com/bar/delete/1</a></li>
    </ol>
  </blockquote>
  
  <p>The issue I'm having is that currently {username} gets treated as an action so to work around the problem I implemented the following routes, but this would mean that every time I want to implement a new action, or have a controller that needs {username}, I would have to update my routes: </p>
  
  <p><strong>Only Foo routes shown</strong></p>
  
  <pre><code>routes.MapRoute("FooSomeAction", "foo/someaction", new { controller = "Food", action = "SomeAction" });            
  routes.MapRoute("FooDelete", "foo/delete/{id}", new { controller = "Food", action = "Delete" });            
  
  
  routes.MapRoute(
      "FooProfile",
      "foo/{username}",
      new { controller = "Foo", action = "Index", username = "" }
  );
  
  
  // Default route
  routes.MapRoute(
      "Default", // Route name
      "{controller}/{action}/{id}",
      new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  );
  </code></pre>
  
  <p><strong>2 Questions</strong></p>
  
  <p>1) Is there any way I can achieve the above urls without hardcoding all the routes?</p>
  
  <p>2) What is the best way to handle a situation where someone uses a username that happens to be the same name as a controller or action name?</p>
  
  <p>DotnetShadow</p>