1

I want to have multiple controllers with the same name, on different paths. For example:

/abc/security/login
/xyz/security/login

This leads to 404 error. When removing the duplicate controller, the error is gone.

I have setup attribute routing like so:

namespace Controllers.Abc
{
    [RoutePrefix("abc/security")]
    public class SecurityController : ApiController
    {
        [Route("login")]
        [HttpPost]
        public IHttpActionResult Login([FromBody] LoginRequestModel requestModel)
        {

namespace Controllers.Xyz
{
    [RoutePrefix("xyz/security")]
    public class SecurityController : ApiController
    {
        [Route("login")]
        [HttpPost]
        public IHttpActionResult Login([FromBody] LoginRequestModel requestModel)
        {

This is .NET Framework Web Api.

  • Is your Register method being called in your Global.asax's applicationstart method (assuming this is not OWIN)? – Jonathon Chase Jun 05 '18 at 19:01
  • Yes, `GlobalConfiguration.Configure(WebApiConfig.Register);` –  Jun 05 '18 at 19:02
  • When you say multiple controllers with the same name, do you mean two different `SecurityController`'s that are in different namespaces? – Jonathon Chase Jun 05 '18 at 19:08
  • Yes, that is exactly what I have. –  Jun 05 '18 at 19:09
  • You should take a [look at this](https://stackoverflow.com/questions/27933731/ambiguous-controller-names-with-routing-attributes-controllers-with-same-name-a). It looks like you'll need a custom implementation of `IHttpControllerSelector` to handle this use case. – Jonathon Chase Jun 05 '18 at 19:12
  • Your requirement is very similar to [API Versioning](https://stackoverflow.com/a/42373994/296861). – Win Jun 05 '18 at 19:26
  • Thank you, Win, it is perfect. –  Jun 05 '18 at 20:06

0 Answers0