title: 400 Bad Request for URLs containing "&" on IIS7 with UrlRoutingModule
body: <p>I'm setting up ASP.net MVC 2.0 on an old WebForms site that runs on IIS 7. The old site has a 404 handler set up like:</p>
  
  <pre><code>&lt;httpErrors errorMode="Custom"&gt;
      &lt;remove statusCode="404" subStatusCode="-1" /&gt;
      &lt;error statusCode="404" prefixLanguageFilePath="C:\..." path="/error404.aspx" responseMode="ExecuteURL" /&gt;
  &lt;/httpErrors&gt;
  </code></pre>
  
  <p>This 404 handler is used to simulate URL rewriting, so a URL like "/+yes-&amp;-no" would get routed to it, and Server.Transfer()ed to the correct page. This all works.</p>
  
  <p>When setting up ASP.net MVC 2.0, I add this to the web.config:</p>
  
  <pre><code>&lt;modules runAllManagedModulesForAllRequests="false"&gt;
      &lt;remove name="UrlRoutingModule" /&gt;
      &lt;add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
  &lt;/modules&gt;
  </code></pre>
  
  <p>Once this is added, all URLs containing an ampersand (e.g. "/+yes-&amp;-no") return:</p>
  
  <blockquote>
    <p>Bad Request</p>
  </blockquote>
  
  <p><strong>How do I keep the UrlRoutingModule enabled, and still allow URLs with ampersand?</strong></p>
  
  <p><strong>Rejected Solutions:</strong></p>
  
  <ol>
  <li>I was able to get <a href="http://dirk.net/2008/06/09/ampersand-the-request-url-in-iis7/" rel="nofollow">these registry changes</a> to work, but they have been vetoed out of security concerns. </li>
  <li><p>I was able to use URL Rewriting to change the "&amp;" to "and", but that has SEO implications because that changes the &lt;h1&gt;, etc.</p>
  
  <p>&lt;rule name="RemoveIllegalAmpersands"&gt;
      &lt;match url="(+.<em>)&amp;(.</em>))" /&gt;
      &lt;action type="Rewrite" url="{R:1}and{R:2}" /&gt;
  &lt;/rule&gt;</p></li>
  <li><p>I saw the <a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.requestpathinvalidcharacters.aspx" rel="nofollow">requestPathInvalidCharacters</a>, web.config element but we can't try it because we're still on .NET 3.5</p></li>
  </ol>
  
  <p><strong>Are there any other solutions that I've missed?</strong></p>