7

I have the following routing attribute in place:

[HttpGet("{id}/foo")]

My id is a base64 encoded value, and, as such, may contain a forward slash. I'm encoding this forward slash using %2F, however, it seems like ASP.NET Core MVC decodes the URL, then matches routes, as I'm getting a 404 if my id contains %2F.

Is there any way I can allow %2F in my id?

I know there are some answers out there (e.g. How to match web api 2 route with forward slashes in request parameters?), but with all of them, the parameter in question, is always the last, and only then you can use a wildcard (?).

HelloWorld
  • 3,381
  • 5
  • 32
  • 58
  • Maybe dare to try ASP.NET Core 2.2-preview3? See [ASP.NET Core 2.2-preview3](https://blogs.msdn.microsoft.com/webdev/2018/10/17/asp-net-core-2-2-0-preview3-now-available/) blog in the Routing section for the new `slugify` routes. Not sure it works for incoming routes, but will for sure work with Url generation – Tseng Nov 10 '18 at 16:19
  • 1
    Sorry, wrong article. It's [ASP.NET Core 2.2-preview1](https://blogs.msdn.microsoft.com/webdev/2018/08/27/asp-net-core-2-2-0-preview1-endpoint-routing/) about the new Endpoint Routing, look down to "New round-tripping route parameter syntax". – Tseng Nov 10 '18 at 16:23
  • Hey, I have the same issue, using AspNetCore 2.2 – neleus Sep 26 '19 at 10:43
  • same issue with .net core 3.1 – Joba Dec 14 '20 at 18:21
  • I know it's dirty, but why not simply replace all forward slashes with a character that isn't in the Base64 alphabet (such as a underscore) and then replace them with forward slashes in the receiving controller? – CB01 Apr 19 '21 at 16:46
  • for those who found this from Google, here is [an answer](https://stackoverflow.com/a/30994100/553073) that could be helpful. basically encode the input twice, and decode it properly in the server side. – lastr2d2 Aug 24 '21 at 07:46

0 Answers0