Web Api 2 routing issue with special characters in

2020-04-12 13:07发布

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

2条回答
别忘想泡老子
2楼-- · 2020-04-12 13:28

UrlEncodeUnicode and UrlDecode should be helpfull in your case.

查看更多
孤傲高冷的网名
3楼-- · 2020-04-12 13:34

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

查看更多
登录 后发表回答