Aspnet-api-versioning: Asp Net Core 2.0 Razor pages UnsupportedApiVersion

Created on 26 Sep 2017  路  12Comments  路  Source: microsoft/aspnet-api-versioning

I have a project mixing simple Razor Pages and WebAPI. After installing versioning I can not access Razor Pages with the error "UnsupportedApiVersion". I specified AssumeDefaultVersionWhenUnspecified =true and defined a default in startup but still get the error. The ApiVersion and MapToVersion don't seem to apply to razor pages. Is there any way to make Razor pages either ApiVersionNeutral or inherit the default version?

asp.net core enhancement investigate question

All 12 comments

Using MVC with API versioning enabled is a supported scenario. If you can share your configuration and/or the world's smallest repro, I can help you iron out the setup. It's possible your configuration may have hit an edge case. I've encountered them before. I add each such case to the acceptance tests to make sure that UI and API routes play nice together. Hopefully, this is just be a simple case of misconfiguration.

Thanks for taking a look at this. Simple Repro project located at https://github.com/paul-xtr/apiversioning

Configuration used in startup
` services.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0);

        });`

Along with a simple razor page TestRP. Hopefully I'm not missing something obvious.

Thanks so much for the repro. There is definitely an issue. While I know normal Razor Views work, I haven't played much with the new, shiny Razor Pages. API Versioning relies quite heavily on applying model conventions. I need to figure out how or if that's even possible. If it's not possible, then I need to somehow generically figure out how to ignore versioning strategies for such routes. Today, there is no special consideration for UI versus API routes.

Thanks for the confirmation. A possibility to allow Razor Pages to just run before deciding on a convention based approach may be to adapt the route constraint to check if the route values page 'property' is set (or even controller value empty) and return true. From what I have seen for razor pages controller is empty and page value is set. I'm definitely not an expert so it's just a thought.

I am on 2.0 and I also am experiencing UnsupportedApiVersion on razor pages

Looks like this merge is not current build / available.

Is it possible to provide a workaround?

Apologies if you were waiting on this. The newest package versions are published. This fix is in the new packages. Let me know if you encounter any new issues. Thanks.

Cool, thanks @commonsensesoftware - i was just trying to upgrade to 2.0 and razor pages and found the issue. THanks for pushing updated packages.

I am on 2.0 and I also am experiencing UnsupportedApiVersion on razor pages

2.1+ allows Razor Pages to pass through

2.1+ allows Razor Pages to pass through

Sorry to say, but adding

services.AddApiVersioning(options =>
{
  options.DefaultApiVersion = new ApiVersion(1, 0);
  options.AssumeDefaultVersionWhenUnspecified = true;
});

and

app.UseEndpoints(endpoints =>
{
  endpoints.MapRazorPages();
  endpoints.MapFallbackToPage("/Index");
});

to a NET5.0 Razor Pages project created from the default template also throws the UnsupportedApiVersion error:

{"error":{"code":"UnsupportedApiVersion","message":"The HTTP resource that matches the request URI 'http://localhost:5000/' is not supported.","innerError":null}}

Referenced ApiExplorer is 5.0.0-preview.1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jarlotee picture Jarlotee  路  5Comments

milla picture milla  路  4Comments

lansman picture lansman  路  5Comments

snebjorn picture snebjorn  路  6Comments

mralj picture mralj  路  4Comments