Search code examples
asp.net-web-apiforwardslash

why web api(RestFul) .NetCore service is not accepting forward slash in parameters, how to resolve this issue


I am using webApi(RESTFUL service) and Angular as front end. I need to call one end point and my parameters has "forward slash"(/). I am encoding parameter string and calling endpoint. but my webApi giving handler error "URL" not found. could you please tell me how I need to fix this one.

my url: https://localhost:44356/api/v1/sample/sampleget/Arts%2Fscience%20course/All

Encoded string: Arts%2Fscience%20course original string: Arts/science course

could any one please help me , how I need to resolve the problem in Angular/ webApi


Solution

  • In order to send a string which has / (slashes) in it, we can use the wildcard parameters in the route. Something like this:

    Route("sampleget/{*course}")

    This will allow for a chunk of a URL with multiple / characters to be read as a single parameter.

    Hope it helps.