I have a web API project, with the following endpoint:
GET api/search/{searchValue}
Controller code:
[RoutePrefix("api/Search")]
public class SearchController : ApiController
{
[HttpGet]
[Route("{searchValue}", Name = "GenericSearch")]
[ResponseType(typeof(SearchResponse))]
public async Task<IHttpActionResult> Search(string searchValue) {
...
}
}
This works fine for most search strings. But if the search string ends in a period (.
) character, the request breaks with a 404; it seems to be interpreting the period as part of the path rather than as part of the query. This is so, even if the request string is Url encoded, e.g.
api/search/foo%2E
If the period is not the last character of the string, it works:
api/search/foo%2Ebar
will correctly search for "foo.bar".
How can I fix this so that users are allowed to search for strings that end with a period character?
UPDATE: After having this question closed as a duplicate of this question, allow me to clarify why this question is different:
- The linked question is trying to use a literal period character in the query string. I'm not even doing that; I'm encoding the
.
as%2E
, and it's still not working. - The query works with the period character in the middle. It's only when it's at the end of the query string that it fails.
- I already have
<modules runAllManagedModulesForAllRequests="true" />
(as suggested by the accepted answer in myweb.config
. - I tried suffixing the query with a slash character (i.e.
api\search\foo%2E\
) as suggested in the highest-voted answer; this made no difference. - I tried all the answers suggested there, and none of them made a difference.