title: API versioning in .NET application
body: <p>I need some clarification on API versioning in .Net Core framework.</p>
  
  <p>My client want the version to be handled in Router level. Like</p>
  
  <pre><code>[Route("1/[controller]")]
  public class SampleController : Controller
  {
      [HttpGet("version")]
      public IActionResult GetVersion()
      {
          return Ok({"Message": "API Version 1"});
      }
  }
  </code></pre>
  
  <p>I access this using, <a href="https://www.somedomain.com/api/1/sample/version" rel="nofollow noreferrer">https://www.somedomain.com/api/1/sample/version</a></p>
  
  <p>In IIS, I will create an application called 'api' (The path 'api' in my URL will be taken care here) under default web site and host my code here.</p>
  
  <p>In order to do API versioning, what is the better way that I can follow here.</p>
  
  <ol>
  <li><p>Can I do this?</p>
  
  <pre><code>[ApiVersion("1")]
  [Route("{version:apiVersion}/[controller]")]
  public class SampleController : Controller
  {
      [HttpGet("version")]
      public IActionResult GetVersion()
      {
         return Ok({"Message": "API Version 1"});
      }
  
      [HttpGet("version"), MapToApiVersion("2" )]
      public IActionResult GetVersion()
      {
          return Ok({"Message": "API Version 2"});
      }
  }
  </code></pre></li>
  <li><p>Is it possible to create an application under an application in IIS. Like,</p></li>
  </ol>
  
  <blockquote>
    <p>Default Web Site - > api -> 1 -> Code without API version mentioned</p>
    
    <p>Default Web Site - > api -> 2 -> Updated Code without API version mentioned</p>
  </blockquote>
  
  <ol start="3">
  <li>Or can I create the versions as application in IIS and deploy the code under each applciation version. Like, </li>
  </ol>
  
  <blockquote>
    <p>Default Web Site - > 1 -> Code without API version mentioned</p>
    
    <p>Default Web Site - > 2 -> Updated Code without API version mentioned</p>
  </blockquote>
  
  <p>This will end up in changing my API URL, which i don't prefer. I still want to go with the same URI.<br>
  I access this using, <a href="https://www.somedomain.com/api/1/sample/version" rel="nofollow noreferrer">https://www.somedomain.com/api/1/sample/version</a></p>
  
  <p>Please advise the best approach that I can follow here.</p>