title: .net core api hierarchical routing
body: <p>I'm building an api, and I want to be able to use hierarchical routing such as:</p>
  
  <pre><code>api/category/1234/product
  api/category/1234/product/5678
  </code></pre>
  
  <p>Currently I'm using a <em>Route</em> attribute on the <strong>ProductController:</strong> <code>[Route("api/[controller]")]</code> This is because most of my routing follows that convention.</p>
  
  <p>I have a method on the <strong>ProductController:</strong></p>
  
  <pre><code>[HttpGet]
  [Route("/api/category/{categoryId:int}/product")]
  public IActionResult GetAllByCategoryId(int categoryId)
  {
      var products = _productRepo.Query(p =&gt; p.CategoryId == categoryId);
  
      return Ok(products);
  }
  </code></pre>
  
  <p>Hooray, it returns data for <code>api/category/{categoryId:int}/product</code></p>
  
  <p>but it will still return the data for <code>api/product/{categoryId:int}</code> because of the <em>Route</em> attribute on the controller.</p>
  
  <p><strong>My question is:</strong></p>
  
  <p>Is there a way to override the controller route template?</p>
  
  <p>The only alternative option I can think of at the moment is to place a <em>Route</em> attribute on every single method. There has to be a better way to deal with hierarchical routing.</p>