Web Api 2 routing issue with special characters in

2020-04-12 13:05发布

问题:

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

回答1:

UrlEncodeUnicode and UrlDecode should be helpfull in your case.



回答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}'