GetRights([FromRoute]st...">

Provide an option on FromRouteAttribute that allows decoding the value being bound (original) (raw)

The rights of my users are at /api/admin/users/{userId}/rights

And my controller is as simple as

[Route("/api/admin/users/{userId}/rights")] public async Task GetRights([FromRoute]string userId) { var rights = await _someService.GetRights(userId); return Ok(rights); }

or

[HttpPut("{userId}")] public async Task Update(string userId, [FromBody]UpdateUserViewModel parameters) { var user = await _employeService.Update(userId, parameters); return Ok(user); }

The problem I have is that, the userIds of my users may contains a / which is encoded to %2F in the Uri. But userId doesn't decode %2F so my string contains %2F. It's fine for me, I can deal with that.

But the userIds of my users may contains a + which is encoded to %2B in the Uri. And now, the userId decode the %2B to + 😲

Currently, I can't use WebUtility.UrlDecode(userId) because userId may contains a + which would be send as %2B decoded as + and finally to ``. My only actual solution is to replace %2F to / which is ugly and does not solve all the possibility : %252F

I saw a recommandation to use [FromQuery] instead of [FromRoute] but it's obvious that if both exist, it's because they have semantic difference.

It seems that's not the first time the problem appears : aspnet/Mvc#4599, #2655, #4445 and I'd like to know if it's on the roadmap to change this behavior or not.

Could you please this time consider this bug ? I'd be happy to help.