简体   繁体   English

Web Api 2路由问题,URL中带有特殊字符

[英]Web Api 2 routing issue with special characters in URL

In the middle of developing a Web Api 2 REST service, we have discovered a routing problem. 在开发Web Api 2 REST服务的过程中,我们发现了路由问题。 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. 问题在于电子邮件中可能包含特殊字符,例如'+',这导致找不到404资源。

We would really like for the user of the service, to be able to specify the email in the URL. 我们真的希望服务的用户能够在URL中指定电子邮件。 But since the email also legally can contain an '&', this can't just be moved to an URL parameter. 但是由于电子邮件在法律上也可以包含“&”,因此不能仅将其移至URL参数。 How would we go about solving this? 我们将如何解决这个问题?

Regards Frederik 问候弗雷德里克

UrlEncodeUnicodeUrlDecode在您的情况下应该会有所帮助。

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}' www.yourwebsite.com/api/account/create?email ='{带有任何字符的电子邮件}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM