Skip to content

Asp Net Core 2.0 Razor pages UnsupportedApiVersion #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
paul-xtr opened this issue Sep 26, 2017 · 12 comments
Closed

Asp Net Core 2.0 Razor pages UnsupportedApiVersion #189

paul-xtr opened this issue Sep 26, 2017 · 12 comments

Comments

@paul-xtr
Copy link

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?

@commonsensesoftware
Copy link
Collaborator

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.

@paul-xtr
Copy link
Author

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.

@commonsensesoftware
Copy link
Collaborator

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.

@paul-xtr
Copy link
Author

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.

@pksorensen
Copy link

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

@pksorensen
Copy link

Looks like this merge is not current build / available.

@pksorensen
Copy link

Is it possible to provide a workaround?

@commonsensesoftware
Copy link
Collaborator

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.

@pksorensen
Copy link

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

@Seanxwy
Copy link

Seanxwy commented Mar 19, 2018

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

@commonsensesoftware
Copy link
Collaborator

2.1+ allows Razor Pages to pass through

@DNF-SaS
Copy link

DNF-SaS commented Oct 21, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants