我有一个基本控制器,可以执行少量发布和获取优惠,下面我给出了一个get
的示例结构[AxAuthorization(Resource = "Offers")]
[RoutePrefix("api/offer/v2/offers")]
public class OffersV2Controller : ApiController
{
[HttpGet]
[Route("{id}", Name = "OffersGetById")]
public async Task<HttpResponseMessage> GetById([FromUri(Name = "id")]string OfferId)
{
----
-----
}
}
我们通过api / offer / v2 / offers / id调用这个get方法,但是其他一些使用我们服务的消费者,他们喜欢称之为api / v2 / offers / id,我们有什么办法可以覆盖它?上面的代码是由产品生成的一种代码,我们不想修改路由前缀。
答案 0 :(得分:0)
[Route("api/v2/offer/test")]
[Route("api/offer/v2/test")]
OR
config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "route1", routeTemplate: "test/v2/Values", defaults: new { controller = "Values", action = "Get" });
config.Routes.MapHttpRoute(
name: "route2",
routeTemplate: "v2/test/Values",
defaults: new { controller = "Values", action = "Get" });
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
webapiConfig.cs中的