ASP.NET Web API multiple RoutePrefix

后端 未结 1 1245
天涯浪人
天涯浪人 2021-02-12 12:17

The opensource Attribute Routing allows to have multiple route-prefixes. Why does ASP.NET Web API 2.0 does not allow to have multiple RoutePrefix().

[RoutePrefix         


        
1条回答
  •  一整个雨季
    2021-02-12 12:31

    You can add a route to the action method also overriding the RoutePrefix with a "~"

    example:

    [RoutePrefix("api/v1/{abc}/Entity")]
    public class MyApiController : ApiController
    {
       [Route("")]
       [Route("~/api/v1/{abc}/{xyz?}/Entity")]
       public IHttpResult Get()
       {
          return Ok("Hello World");
       }
    }
    

    Notice the line: [Route("~/ api/v1/{abc}/{xyz?}/Entity")]

    0 讨论(0)
提交回复
热议问题