title: Passing two parameters as composite primary key to HttpGet Attribute
body: <p>I have two issues here. I'm doing .NET core web REST API. (core 2.0). I have a linking table that has primary key consisting of two columns (composite primary key). How can I pass both (two columns) parameters to <code>[HttpGet]</code> attribute in order to get data by its database id ? I used <code>/</code> character like this post suggested : <a href="https://stackoverflow.com/questions/37063448/mvc6-attribute-routing-with-two-parameters">MVC6 attribute routing with two parameters</a> but it doesn't work for me. I always get my more general <code>[HttpGet]</code> action invoced without any parameters instead of <code>GetUserPermissionByID()</code>. <code>GetUserPermissionByID()</code> is never invoked.</p>
  
  <p>Second issue is connected with the first one. While creating an object in the same controller in <code>[HttpPost]</code> action I'm using <code>CreatedAtRoute()</code> method to pass newly created object to client. But how to write it correctly to send it back with composite primary key as ID ? </p>
  
  <p>my code :</p>
  
  <p><strong>MODEL</strong></p>
  
  <pre><code>public class UserPermission
  {
      public int IDUser { get; set; }
      public int IDPermission { get; set; }
      public User User { get; set; }
      public Permission Permission { get; set; }
  }
  </code></pre>
  
  <p><strong>CONTROLLER - GET BY ID</strong></p>
  
  <pre><code>[HttpGet("{idUser}/{idPermission}", Name = "GetUserPermissionByID")]
  public async Task&lt;IActionResult&gt; GetUserPermissionByID(int idUser, int idPermission)
  {
      try
      {
          var userPermission = _context.UsersPermissions.Where(up =&gt; up.IDUser == idUser &amp;&amp; up.IDPermission == idPermission).FirstOrDefaultAsync();
  
          if (userPermission == null)
          {
              return NotFound();
          }
          else
          {
              return new ObjectResult(userPermission);
          }
      }
      catch (System.Exception ex)
      {
          Helpers.ExceptionLogger.LogException(ex);
          return StatusCode(500);
      }
  }
  </code></pre>
  
  <p><strong>CONTROLLER - POST</strong></p>
  
  <pre><code>[HttpPost]
  public async Task&lt;IActionResult&gt; CreateUnitPermission([FromBody] UserPermission userPermissionToCreate)
  {
      if (userPermissionToCreate == null)
      {
          return BadRequest();
      }
      else
      {
          try
          {
              _context.UsersPermissions.Add(userPermissionToCreate);
  
              await _context.SaveChangesAsync();
  
              return CreatedAtRoute("GetUserPermissionByID", new { id = new { userPermissionToCreate.IDUser, userPermissionToCreate.IDPermission } }, userPermissionToCreate); // it doesn't work 
          }
          catch (Exception ex)
          {
              Helpers.ExceptionLogger.LogException(ex);
              return StatusCode(500);
          }
      }
  }
  </code></pre>