我正在尝试按照本教程实现 api 版本控制。所以在我的创业中,我有:
var constraintResolver = new DefaultInlineConstraintResolver()
{
ConstraintMap =
{
["apiVersion"] = typeof( ApiVersionRouteConstraint )
}
};
configuration.MapHttpAttributeRoutes(constraintResolver);
configuration.AddApiVersioning()
和我的控制器:
[Route("api/v{version:apiVersion}/my")]
[ApiVersion("1.0")]
[ApiVersion("2.0")]
public class MyV1Controller
[Route("api/v{version:apiVersion}/my")]
[ApiVersion("3.0")]
public class MyV3Controller
当我请求http://localhost/api/v1.0/my时出现错误
Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.\r\n\r\nThe request has found the following matching controller types: \r\nMyV1Controller\r\nMyV2Controller
您能否建议如何使控制器版本控制工作?