title: Customizing ASP.NET MVC Routing to service ".json" ".xml" Style Urls
body: <p>I have a search Api I'm working on that needs to return search results in a block of Html (using styles the client has defined on their end). I would also like to return results in Json, for future Api stuff we'll eventually be using. Currently, the routes look like this:</p>
  
  <pre><code>/api/1/search/json?param1=blah&amp;param2=blah&amp;etc
  /api/1/search/html?param1=blah&amp;param2=blah&amp;etc
  </code></pre>
  
  <p>For reference, the pattern here is /{area}/1/{controller}/{action}.</p>
  
  <p>I like the look of some Api's I've seen that return results in different formats depending on the 'extension' they have in the url, a la:</p>
  
  <pre><code>/api/1/search.json?param1=blah&amp;param2=blah&amp;etc
  </code></pre>
  
  <p>However, I haven't figured out how to configure Asp.Net's Mvc routing to support this style. The general routing in ApiAreaRegistration.cs is:</p>
  
  <pre><code>context.MapRoute(
      "Api_default",
      "Api/1/{controller}/{action}/{id}",
      new { action = "Index", id = UrlParameter.Optional });
  </code></pre>
  
  <p>I have tried the following, defined above the general one, which doesn't work:</p>
  
  <pre><code>//search api
  context.MapRoute(
      "searchJson",
      "api/1/{controller}.{action}",
      new { controller = "SearchController" });
  </code></pre>
  
  <p>How would I configure routing to enable the .format-style urls?</p>