locked
WebAPI - Passing ''+" in the Url. RRS feed

  • Question

  • User633086528 posted

    Hi,

    A GET call by the following Url :

    http://mydomain.com/v1/Observers/my+email@email.com

    is throwing error -

    An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code

    Additional information: The remote server returned an error: (404) Not Found.

    Route: [Route("v1/Observers/{id}]

    Please help me in resolving the issue.

    Friday, June 26, 2015 12:52 AM

Answers

  • User1881638666 posted

    Hi,

    Without encoding special characters in the route url, add them to query string.

    You can call it via following route and url,

    [Route("v1/Observers")]

    public string GetUser(string id){

    }

    Call this by,

    http://mydomain.com/v1/Observers?id=my%2Bemail@email.com

    Thanks,

    Wenushka

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 26, 2015 1:57 AM
  • User-138691462 posted

    There are 2 or 3 ways to resolve your problem. 

    1. If you define your route as [Route("v1/Observers/{id}], you must call it like this http://mydomain.com/v1/Observers/id=my+email@email.com

    2. if you wanna to support + and other chars like ~,#, you can change your code to support that. One way to support it is encode your url, the other way is to change your web config to allow that:  Google for allowDoubleEscaping In .net.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 28, 2015 11:24 PM

All replies

  • User1881638666 posted

    Hi,

    Without encoding special characters in the route url, add them to query string.

    You can call it via following route and url,

    [Route("v1/Observers")]

    public string GetUser(string id){

    }

    Call this by,

    http://mydomain.com/v1/Observers?id=my%2Bemail@email.com

    Thanks,

    Wenushka

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 26, 2015 1:57 AM
  • User-138691462 posted

    There are 2 or 3 ways to resolve your problem. 

    1. If you define your route as [Route("v1/Observers/{id}], you must call it like this http://mydomain.com/v1/Observers/id=my+email@email.com

    2. if you wanna to support + and other chars like ~,#, you can change your code to support that. One way to support it is encode your url, the other way is to change your web config to allow that:  Google for allowDoubleEscaping In .net.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 28, 2015 11:24 PM
  • User633086528 posted

    Hi Rocky,

    Thanks for helping me up.

    Regarding the point # 2, Simply encoding the url doesn't works. Allowing Double Escaping is a security risk i guess.

    Another way is to encrypt the url with BASE64.

    Monday, June 29, 2015 5:35 AM
  • User633086528 posted

    Hi Wenushka,

    Thanks for helping me up.

    I did it using the BASE64 encoding and it worked like charm. With this approach , we don't need to change the routes and all.

    Monday, June 29, 2015 5:37 AM