0

With a routing and controller

[HttpGet]
[Route("api/test/{term}")]
public IHttpActionResult Get(string term)
{
}

I want the request to api/test/1%20 (UrlEncoded "1 ") be populated to the term parameter as a "1 " value. I've enabled the <httpRuntime relaxedUrlToFileSystemMapping="true" /> in system.web section of web.config so the requests are coming through, however, the trailing space is removed.

The endpoint is used for some sort of suggestion functionality therefore values "1" and "1 " returns different results.

All discussions about potential solution I was able to find are talking more about howto accept such request:

WebAPI route 404's when there is a trailing space in the URL

Allowing reserved filenames in URLs

Community
  • 1
  • 1
luk355
  • 530
  • 4
  • 6
  • You can add a trailing slash to force it to pass trailing space. http://example.com/api/1%20/ – Hakunamatata May 03 '17 at 05:09
  • yep, that works @Hakunamatata, thanks for the advice. I realized I need to support also terms like `"11/"`which then breaks the routing so I ended up taking the `term` parametr from query string. – luk355 May 03 '17 at 23:18

1 Answers1

0

The tip shared by Hakunamatata to add a trailing slash works for terms like "1 " however still doesn't support strings containg slash characters which I needed to support as well. I ended up taking term parameter from query string.

[HttpGet]
[Route("api/test")]
public IHttpActionResult Get(string term)
{
}

supporting request format api/test?term=TERM i.e. api/test?term=1%20%2f

luk355
  • 530
  • 4
  • 6