Route Prefix VS Controller Name (Web api)

I was wondering if we use the attribute RoutePrefixin our api web controller with a different name from the actual controller name. So will it work or not?

As far as i knew

[RouterPrefix("quotation")]
public class SaleOrderController : ApiController { ... }

if we determine RoutePrefix, as indicated above, we cannot access it through /quotation, but we can access it with saleorder.

So what is it RoutePrefixor am I doing something wrong?

+4
source share
2 answers

To use the default route usage Route("")

[RouterPrefix("quotation")]
public class SaleOrderController : ApiController {

    //GET quotation
    [Route("")]
    [HttpGet]
    public IHttpActionResult GetAll() { ... }

}

: ASP.NET Web API 2:

+3

, WebApiConfig.Register():

config.MapHttpAttributeRoutes();

, RoutePrefix exptected:

[RoutePrefix("quotation")]
public class SaleOrderController : ApiController
{
    [Route("example")]
    [HttpGet]
    public IHttpActionResult Example()
    {
        return Ok();
    }

    [Route("another")]
    [HttpGet]
    public IHttpActionResult Another()
    {
        return Ok();
    }

}

, apis :

  • /
  • /
+3

Source: https://habr.com/ru/post/1667764/


All Articles