title: Wcf Web Api service routes conflicting with regular asp.net mvc routes (web api preview 4)
body: <p>I noticed that my mvc app is creating wrong url's when using:</p>
  
  <pre><code>@using (Html.BeginForm("Test", "Test"))
  {
      &lt;input type="submit" value="Submit" /&gt;
  }
  </code></pre>
  
  <p>This is the generated html source:</p>
  
  <pre><code>&lt;form action="/books?action=Test&amp;amp;controller=Test" method="post"&gt;
  </code></pre>
  
  <p>Notice that action starts with <strong>/books</strong>. This is WRONG!</p>
  
  <p>What I've noticed is that Html.BeginForm is always including the beginning of the first web api which has been registered with MapServiceRoute. (see code below)</p>
  
  <pre><code>public static void RegisterRoutes(RouteCollection routes)
  {
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
      var builder = HttpHostConfiguration.Create();
      routes.MapServiceRoute&lt;BooksService&gt;("books", builder);
  
      routes.MapRoute(
          "Default", // Route name
          "{controller}/{action}/{id}", // URL with parameters
          new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
      );
  }
  </code></pre>
  
  <p>I spent a long time trying to figure out why the url's were broken in my app, but got nowhere.
  I then decided to test with an extremly simple mvc app and sure enough the problem can be easily reproduced.
  The mvc app I tested this on is as simple as it can get, was created by an asp mvp. You can find it <a href="https://msmvps.com/blogs/theproblemsolver/archive/2011/06/13/using-the-wcf-web-api-in-an-asp-net-mvc-application.aspx" rel="nofollow">here</a>. All I did was add the TestController and the Views/Test/Index.cshtml view. In the view I added the Html.BeginForm shown above. If you launch the app and visit the test controller you can see the url is wrong by just hovering the mouse over the submit button (or look at the html source).</p>
  
  <p>Anyone know how to avoid this problem?</p>
  
  <p><strong>EDIT</strong>:
  This applies for web api preview 4 (april 2011).</p>