-
Notifications
You must be signed in to change notification settings - Fork 709
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
.NET 8 ASP Versioning is allowing any version number to be passed in to api request and returns data. #1093
Comments
It appears you are migrating from an earlier version and you've missed adding private void ConfigureApiVersioning(IServiceCollection services)
{
services
.AddApiVersioning(options => options.ReportApiVersions = true)
.AddMvc() // required in 6.0+ for MVC Core with controllers
.AddApiExplorer(options =>
{
options.DefaultApiVersion = new ApiVersion(1, 0);
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
});
} |
hey @commonsensesoftware, thanks for the reply. I just spun up a fresh api and seem to be able to dupe this issue. here is my program.cs var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Configure the HTTP request pipeline. app.UseHttpsRedirection(); app.UseAuthorization(); }); app.MapControllers(); app.Run(); void ConfigureApiVersioning(IServiceCollection services) => services and here is the small change to the demo controller: namespace NET8VersioningTest.Controllers Probably something dumb I am doing, but any suggestion would be greatly appreciated! |
this works actually. Setting options.EnableEndpointRouting = True and removing the lines: app.UseMvc(options => }); fixed it. Thanks for your time. |
I definitely would not recommend using the legacy I think there may be some confusion as to what is happening. builder.Services.AddMvcCore(); // or .AddMvc() is NOT the same as: builder.Services.AddApiVersioning().AddMvc(); The first one brings in MVC Core (or full MVC). The second one adds MVC (Core) support for API Versioning. |
Versioning was working for me in the sample WeatherForecast api I spun up, but wouldn't work in our actual project. I noticed that our Controller was missing the [APIController] Attribute. Once I added that attribute, versioning started to work great. |
Is there an existing issue for this?
Describe the bug
I only want routing for v1. any other integer version should 404.
Currently I can pass through any integer and get back data as if it was calling v1.
ex) GET https://somedomain/app/api/v25/resouce/641B3CAA-1229-4AC2-BA9A-73534B7E9D4C
returns the same as https://somedomain/app/api/v1/resouce/641B3CAA-1229-4AC2-BA9A-73534B7E9D4C
Expected Behavior
only v1 should hit my v1 controller. v25, v2, v8, etc should all 404.
Steps To Reproduce
using fairly boiler plate setup
in startup:
private void ConfigureApiVersioning(IServiceCollection services)
{
services
.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
})
.AddApiExplorer(options =>
{
options.DefaultApiVersion = new ApiVersion(1, 0);
const string groupNameFormat = "'v'VVV";
options.GroupNameFormat = groupNameFormat;
options.SubstituteApiVersionInUrl = true;
});
}
In my controller:
[ApiVersion("1.0")]
[Route("v{api-version:apiVersion}/someResource")]
[Produces("application/json")]
[Consumes("application/json")]
public class SomeController
Exceptions (if any)
No response
.NET Version
8.0.300
Anything else?
No response
The text was updated successfully, but these errors were encountered: