FromRoute parameters aren't URL Decoded. #4599
Description
[HttpGet]
[Route("")]
public async Task<IActionResult> GetValue([FromQuery(Name = "value")] String value) { ... }
[HttpGet]
[Route("{value}")]
public async Task<IActionResult> GetValue([FromRoute(Name = "value")] String value) { ... }
In the first example, a URL encoded string passed as the value
query string parameter will be decoded before being passed into the GetValue
function.
In the second example, a URL encoded string passed as a route segment will NOT be URL decoded before being passed to the GetValue
function.
This behavior is unexpected, I would expect both Route and Query parameters to be URL decoded before being passed to the function.
If this is expected behavior, is there a workaround or a way to tell the route to decode before passing the parameter through? The problem is made more complex in my real world example because the route parameter is a URL and I want the parameter to be a Uri
rather than a String
. My current solution is to accept a String
parameter and then construct a new Uri(value)
out of it. However, this means I don't benefit from ModelState validation since the only a string is necessary to have the model state be valid.