-
Notifications
You must be signed in to change notification settings - Fork 711
Support API Version in URL Generation #663
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
Comments
Hello, Chris. I have an issue even when I do not use version in url.
Am I missing something here? |
From the looks of it, this is simply because you are missing the route parameter in the template. The correct signature should be: [HttpGet("{id}")]
public async Task<string> Get(int id) => $"Hello, {id}!"; It's also worth nothing that the issue with URL generation only exists if you are versioning by URL segment, which you are not (currently) doing and I don't recommend. 😉 |
Unfortunately, even with "{id}" I have the same error. |
Using the BasicExample as the baseline project, I added your example controller as follows: [ApiController]
[Route( "[controller]" )]
public sealed class HomeController : ControllerBase
{
[HttpGet( "{id}" )]
public IActionResult Get( int id ) => Ok( $"Hello, {id}!" );
[HttpPost]
public IActionResult Post() => CreatedAtAction( nameof( Get ), new { id = 42 }, null );
} RequestPOST /home?api-version=1.0 HTTP/2 ResponseHTTP/2 201
Location: http://localhost/home/42
api-supported-versions: 1.0 Hopefully that helps you figure out the difference from your setup. |
Ofc there are differences =)
Get method works fine. But if I omit it or specify |
|
You can inject |
Yes, injecting |
Add support to resolve the current API version as an ambient value during URL generation via the IUrlHelper. Today, URL generation works exactly has it is supposed, but often confuses those that version by URL segment and do not include the API version route parameter as an input value. The default IUrlHelper implementations provided by ASP.NET only consider well-known route parameters (ex:
[controller]
,[action]
, etc) as a possible ambient value.The text was updated successfully, but these errors were encountered: