J
J
Jarwis2015-04-27 09:03:07
ASP.NET
Jarwis, 2015-04-27 09:03:07

Why doesn't ASP.NET see the route through the route attribute?

In general, the project combines both asp.net mvc and asp.net webapi. The problem arises when using Areas and specifying routes for ApiControllers. Two identical classes in different areas (for example, TestController in Site and Manager area). Both have a RoutePrefix attribute. And no asp.net route wants to process. Not from the site area nor from the manager area.

namespace Test.Web.Areas.Site.Controllers {
    [RoutePrefix("api/test")]
    public class TestContoller : ApiController {
             [HttpGet]
             [Route("testone")]
             public IHttpActionResult TestOne() {
                   return Ok(new { test = "OK"});
             }
    }
}

namespace Test.Web.Areas.Manager.Controllers {
    [RoutePrefix("api/test")]
    public class TestContoller : ApiController {
             [HttpGet]
             [Route("testtwo")]
             public IHttpActionResult TestTwo() {
                   return Ok(new { test = "OK2"});
             }
    }
}

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir S, 2015-04-27
@hePPer

in RouteConfig wrote

// Enable attribute routing.
            routes.MapMvcAttributeRoutes();

?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question