您好,我正在使用带有版本控制的 .Net 6 Web API,我的版本控制在 Swagger 中工作得很好,但是当我从 MVC Framework (.NET 6) 引用我的 API 时,我收到一个异常:
InvalidOperationException:约束引用“apiVersion”无法解析为类型。使用“Microsoft.AspNetCore.Routing.RouteOptions.ConstraintMap”注册约束类型。
public static IServiceCollection AddApiVersioningConfig(this IServiceCollection services)
{
services.AddApiVersioning(cfg =>
{
cfg.DefaultApiVersion = new ApiVersion(1, 0);
cfg.AssumeDefaultVersionWhenUnspecified = true; // In case if the user doesn't specify the version, so we assume to use the default one (v1)
cfg.ReportApiVersions = true; // This will mention which API the user is currently using (Header).
// 1- api/v1/clients/ => In order to read the segment that contains …Run Code Online (Sandbox Code Playgroud)