Issues with Microsoft.AspNetCore.Mvc.Versioning apiVersion-Constraint #197

Closed
opened 2025-08-09 17:15:22 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @ngRevan on 1/31/2018

Title

Usage of apiVersion-Constraint from the Microsoft Versioning-Library results in 404 Status Codes.

Functional impact

API controller actions cannot be found when using the Versioning-Library in addition with Spa-Services. Maybe a general problem when using constraints?

Minimal repro steps in current Angular Template

  1. Install Microsoft.AspNetCore.Mvc.Versioning Package
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="2.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.0.0-rc1-final" />
  </ItemGroup>
  1. Configure Api-Versioning in Startup.cs
services.AddApiVersioning(o =>
{
       o.ReportApiVersions = true;
       o.AssumeDefaultVersionWhenUnspecified = true;
       o.DefaultApiVersion = new ApiVersion(1, 0);
});
  1. Add apiVersion-Constraint to SampleDataController
[Route("api/v{apiVersion:apiVersion}/[controller]")]
public class SampleDataController : Controller
{
  1. Modify route in FetchDataComponent to include API-Version
export class FetchDataComponent {
  public forecasts: WeatherForecast[];

  constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
    http.get<WeatherForecast[]>(baseUrl + 'api/v1/SampleData/WeatherForecasts').subscribe(result => {

If you remove all SPA-Services from Startup.cs the api call works as expected.

*Originally created by @ngRevan on 1/31/2018* ### Title Usage of apiVersion-Constraint from the Microsoft Versioning-Library results in 404 Status Codes. ### Functional impact API controller actions cannot be found when using the Versioning-Library in addition with Spa-Services. Maybe a general problem when using constraints? ### Minimal repro steps in current [Angular Template](https://github.com/aspnet/templating/tree/dev/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/Angular-CSharp) 1. Install Microsoft.AspNetCore.Mvc.Versioning Package ~~~~ <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="2.1.0" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.0.0-rc1-final" /> </ItemGroup> ~~~~ 2. Configure Api-Versioning in Startup.cs ~~~~ services.AddApiVersioning(o => { o.ReportApiVersions = true; o.AssumeDefaultVersionWhenUnspecified = true; o.DefaultApiVersion = new ApiVersion(1, 0); }); ~~~~ 3. Add apiVersion-Constraint to SampleDataController ~~~~ [Route("api/v{apiVersion:apiVersion}/[controller]")] public class SampleDataController : Controller { ~~~~ 4. Modify route in FetchDataComponent to include API-Version ~~~~ export class FetchDataComponent { public forecasts: WeatherForecast[]; constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) { http.get<WeatherForecast[]>(baseUrl + 'api/v1/SampleData/WeatherForecasts').subscribe(result => { ~~~~ If you remove all SPA-Services from Startup.cs the api call works as expected.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#197
No description provided.