逃脱+ URI 中的(加号)
当用户在我的网站上输入电子邮件时,我会发送一封包含链接的电子邮件验证电子邮件。链接看起来像:
http://mysite.com/[电子邮件受保护]&token=12341234
此特定用户的电子邮件包含“+”(加号),因此链接如下所示:
http://mysite.com/[email protected]&token=12341234
当链接被单击时(至少在 Firefox 中),plus 替换为一个空间。
问题:我在.net中使用什么URL编码函数来转义加号。
注意:Uri.EscapeUriString(email)
保持 plus 不变。
When user enters an e-mail on my web site, I send an e-mail verification e-mail that contains a link. Link looks something like:
http://mysite.com/[email protected]&token=12341234
This particular user's e-mail contains '+' (plus), so link looks like:
http://mysite.com/[email protected]&token=12341234
when link is clicked (at least in Firefox) plus is replaced with a space.
Question: What URL encoding function do I use in .net to escape the plus.
Note: Uri.EscapeUriString(email)
leaves plus intact.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
Uri.EscapeDataString
相反 - 我刚刚验证了将“Foo+Bar”转换为“Foo%2BBar”。老实说,如果 MS 能够就这些方法以及 HttpUtility.UrlEncode(并非在所有平台上都可用)之间的差异提供更多指导,我将不胜感激。
You can use
Uri.EscapeDataString
instead - I've just verified that that converts "Foo+Bar" into "Foo%2BBar".To be honest, I'd appreciate it if MS provided a little more guidance on the difference between these methods, as well as
HttpUtility.UrlEncode
(which isn't available on all platforms).您可以尝试 UrlEncode 方法:
You could try the UrlEncode method:
您能做的最好的事情就是对电子邮件地址进行散列或加密,或者将其“包含”在您的令牌中。
这样,您的链接就可以如下所示:
http://mysite.com/VerifyEmail?token=12341234480348204023
或者:
http://mysite.com/VerifyEmail?emailcode=A124E4F325O425FE5F4J6636K66L&token= 12341234
如果您遵循哈希路由,请记住 Base64 在编码时也使用
+
作为有效字符。常见的做法是将其替换为 @ 或其他内容:然后,当您执行确认时:
The best thing you can do is to hash or encrypt the e-mail address, or somewhat "include" it on your token.
That way, your link can look like:
http://mysite.com/VerifyEmail?token=12341234480348204023
Or:
http://mysite.com/VerifyEmail?emailcode=A124E4F325O425FE5F4J6636K66L&token=12341234
If you follow the hash route, remember that Base64 also uses
+
as a valid character when encoding. The common practice is to replace it by an @ or something else:Then, when you perform the confirmation: