Comments (4)
This looks like a possible false positive. In the new POST action, it is returning the location header that is generated by using the route template with the key notAGet and the values new { id = 43 }
. Since the route template defined by [HttpPost("notAGet")]
does not have an {id} template parameter, I would expect some type of failure.
To test the theory, I added and modified your example as:
[HttpPost("notAGet")]
public IActionResult NotAGet() => CreatedAtRoute("GetMessageById", new { id = 43 }, null );
The request looks like:
POST /api/v1/helloworld/notAGet HTTP/1.1
Host: localhost
The operation succeeds with the response:
HTTP/1.1 201 Created
api-supported-versions: 1.0
Location: http://localhost/api/v1/HelloWorld/43
In addition, the 500 response that I received clearly indicated that one or more of the route values were not present in the template. Maybe that information is only disclosed during debugging. Let me know if this is not the behavior you are expecting.
from aspnet-api-versioning.
@commonsensesoftware - sorry, my example is probably a bit confusing, so I'll strip it down to the simplest case. Take this controller
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
public class HelloWorldController : Controller
{
[HttpPost("notAGet")]
public IActionResult NotAGet() => Ok();
}
if you issue a GET request as follows:
GET /api/v1/helloworld/notAGet HTTP/1.1
Host: localhost
You get an unhandled ArgumentNullException from the ApiVersioning middleware. It throws at line 26 of Microsoft.AspNetCore.Mvc.Versioning.ActionSelectionContext.cs. This will end up being an Http 500 response.
I think you should get an Http 404 in this instance because there is no matching route for the GET request. At least that is what happens if you do the same thing to a controller in a project without any Api versioning e.g.
[Route("api/[controller]")]
public class HelloWorldController : Controller
{
[HttpPost("notAGet")]
public IActionResult NotAGet() => Ok();
}
GET /api/helloworld/notAGet HTTP/1.1
Host: localhost
Gives a 404...
Hope that makes sense...
from aspnet-api-versioning.
I see. Yes, this is a bug. The original implementation of the ActionSelector class returns null
when no actions are satisfied and I didn't account for that. I've tracked down the issue and will have a published fix in soon. Thanks for reporting this.
from aspnet-api-versioning.
No problem. Thanks for fixing!
from aspnet-api-versioning.
Related Issues (20)
- ASP.NET Web API versioning Migrate from QueryStringApiVersionReader to UrlSegmentApiVersionReader HOT 2
- only the 5.1.0 version of Microsoft.AspNetCore.Mvc.Versioning is deprecated HOT 3
- Problem with describing reponse codes in minimal api HOT 3
- Cannot run APIs with different controller names with same ControllerName attribute after migration HOT 6
- Different options in `ApiVersioningOptions.cs` between .NET Framework and .NET Core packages HOT 2
- WithOpenApi() ignore Api versioning readers HOT 4
- .net 8 support HOT 7
- Breaking changes when migrating to OData8 + new versioning HOT 10
- odata/$metadata returns 404 when all controllers are decorated with ApiVersionNeutralAttribute HOT 3
- AddVersionedApiExplorer not working in Asp.Versioning HOT 5
- VersionedApiDescriptionProvider does not set the correct SunsetPolicy to ApiDescription instances HOT 1
- Using ApiExplorerSettingsAttribute together with ApiVersionAttribute produces unexpected number of ApiVersionDescriptions HOT 5
- Asp.Net Core WebApi - AWS ECS Cluster Authentication failure HOT 2
- [Versioned Clients][API Notifications] Fails to read new versions when available HOT 2
- Swashbuckle documentation inconsistent with examples HOT 2
- AssumeDefaultVersionWhenUnspecified does not work correctly if ApiVersionNeutral is used in the controller HOT 2
- swagger.json file not found after update HOT 9
- My API is not displaying all the versions. HOT 4
- Improve docs for HeaderApiVersionReader
- Add synonym to `AddMvc` method. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspnet-api-versioning.