-
Notifications
You must be signed in to change notification settings - Fork 708
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
Optional parameters don't work #122
Comments
Can you provide a skeleton of one of your controllers and the request URLs that you expect to work? Sharing any additional API versioning configuration that you've specified would also be help (unless it's the default). |
API versioning configuration:
base controller class:
controller derived from basic class:
after POST request to /api/v1.0/people with new person info in request body I want method Post([FromBody]TDto dto, int? id, string[] include) handle this request |
OK ... this is an issue, but not a new one. The problem isn't specifically about optional parameters. You can see another variation in #106. In short, two things cause this behavior:
I don't know how or why - yet, but IActionSelector.SelectBestCandidate is called multiple times by ASP.NET in your scenario and others like it. This is unexpected. The API versioning IActionSelector short-circuits the pipeline and returns 400. Since it will be called 2+ times, this process is happening too early. I'm in the process of tracking down the issue and engaging with the ASP.NET team. This behavior is not documented anywhere. In the meantime, you can work around the problem by making your route templates be the same when they overlap for a single controller. In other words, make them both:
OR
I tried both variations and they work. This is not a solution and is far from ideal, but it should unblock you in the interim. This likely means you'll have to have your own custom validation in one of the paths that you should get for free using the route constraints. |
The 1.1 RC has now been published that resolves this issue. Note that there is breaking, behavioral change for ASP.NET Core to support it. :( You'll now need to call Let me know if you run into anything, but I think 1.1 is ready. |
it works. thank you |
There was controller in asp.net core 1.1 with action method with optional parameter:
It worked. then versioning was added. and this pattern stops work:
with error
If I add constraint to route pattern for method ("[controller]/{id:int?}") it strats work again but only with supplied id value. The only solution I found was adding new action method with url template "[controller]".
Is it error or I missed something?
The text was updated successfully, but these errors were encountered: