title: ASP.NET Web API Attribute Routing To Wrong Action
body: <p>I have applied attribute routing on my controller and it'srouting to wrong action. I don't know where I am getting it wrong.</p>
  
  <p>Here is my controller:</p>
  
  <pre><code>using System.Collections.Generic;
  using System.Web.Http;
  using System.Web.Http.Description;
  using System.Linq;
  using System;
  
  namespace Iboo.API.Controllers
  {
      public class ClientsController : ApiController
      {
          private readonly IClientRepository _repository;
  
          public ClientsController(IClientRepository repository)
          {
              _repository = repository;
          }
  
          // GET: api/Clients
          [Route("api/v1/clients")]
          public IEnumerable&lt;Client&gt; Get()
          {
  
             //code
          }
  
  
          // GET: api/Clients/5
          [HttpGet]
          [ResponseType(typeof(Client))]
          [Route("api/v1/clients/get/{id}")]
          public IHttpActionResult GetClientById(int id)
          {
              //code
          }
  
          // GET: api/Clients/5
          [HttpGet]
          [ResponseType(typeof(string))]
          [Route("api/v1/clients/{id}/emailid")]
          public IHttpActionResult GetClientEmailId(int id)
          {
              //code
          }        
      }
  }
  </code></pre>
  
  <p>I am specifically interested in the <strong>GetClientEmailId</strong> method. Below is my WebApiConfig</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
      // Web API configuration and services
      var container = new UnityContainer();
      container.RegisterType&lt;IClientRepository, ClientRepository&gt;(new 
      HierarchicalLifetimeManager());
  
  
      // Web API routes
      config.MapHttpAttributeRoutes();
  
      config.Routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/v1/{controller}/{id}",
          defaults: new { id = RouteParameter.Optional }
      );
  }
  </code></pre>
  
  <p>My Global.asax.cs is as follows</p>
  
  <pre><code>public class WebApiApplication : System.Web.HttpApplication
  {
      protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
          GlobalConfiguration.Configure(WebApiConfig.Register);
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
          BundleConfig.RegisterBundles(BundleTable.Bundles);
      }
  }
  </code></pre>
  
  <p>In the browser If I type <a href="http://localhost:54919/api/v1/clients/?id=1/getemailid" rel="nofollow noreferrer">http://localhost:54919/api/v1/clients/?id=1/getemailid</a> it's taking me to <a href="http://localhost:54919/api/v1/clients" rel="nofollow noreferrer">http://localhost:54919/api/v1/clients</a> which is not what I want.</p>
  
  <p>If I try <a href="http://localhost:54919/api/v1/clients/1/getemailid" rel="nofollow noreferrer">http://localhost:54919/api/v1/clients/1/getemailid</a> I am getting a 404 error.</p>
  
  <p>I am not sure as to what I'm getting wrong.</p>