Web Api 2 routing issue with special characters in URL

10,260

Solution 1

UrlEncodeUnicode and UrlDecode should be helpfull in your case.

Solution 2

No, encoding and deconding can only work if yyou're in control of the client and server operations. If otherwise, the best way is to call the endpoint as such

www.yourwebsite.com/api/account/create?email='{email with any characters}'

Share:
10,260
Frederik Nygaard Svendsen
Author by

Frederik Nygaard Svendsen

Updated on June 27, 2022

Comments

  • Frederik Nygaard Svendsen
    Frederik Nygaard Svendsen almost 2 years

    In the middle of developing a Web Api 2 REST service, we have discovered a routing problem. The endpoint is as follows:

    .../{email}/...

    The problem is that the email could contain special characters such as '+', which results in a 404 resource not found.

    We would really like for the user of the service, to be able to specify the email in the URL. But since the email also legally can contain an '&', this can't just be moved to an URL parameter. How would we go about solving this?

    Regards Frederik