简体   繁体   English

Firefox中的Server.UrlEncode撇号(')

[英]Server.UrlEncode apostrophe(') in Firefox

So I have a Hyperlink called lnkTwitter: 因此,我有一个名为lnkTwitter的超链接:

And I'm trying to set the url in the code behind: 我试图在后面的代码中设置URL:

lnkTwitter.NavigateUrl = string.Format("http://www.twitter.com/home?status={0}", Server.UrlEncode("I'm Steven"));

When I do that and hover over the link, the url displays correctly in the status bar as " http://www.twitter.com/home?status=I 'm+Steven", but the actual url, if I click on the link or look at the link's properties, is " http://www.twitter.com/home?status=I%27m+Steven ". 当我这样做并将鼠标悬停在链接上时,该URL在状态栏中正确显示为“ http://www.twitter.com/home?status=I'm + Steven”,但是如果我单击,则为实际URL链接或查看链接的属性是“ http://www.twitter.com/home?status=I%27m+Steven ”。

For some reason, this only happens in Firefox; 由于某些原因,这仅在Firefox中发生; in IE, I am taken to the correct url. 在IE中,我被带到正确的URL。

Have you tried to view source code? 您是否尝试查看源代码? If source is ok, then there's no troubles with your code. 如果源没问题,那么您的代码就没有问题了。

Firefox just likes to unescape the urls that it shows. Firefox只喜欢取消显示的网址。 While this can be confusing it should not cause your code or the sites you link to (twitter, in this case) any problems. 虽然这可能会造成混淆,但它不应导致您的代码或链接到的网站(在这种情况下为twitter)引起任何问题。

If you follow the link and then copy the url and paste it into Notepad or something then you should get the escaped form that was actually used instead of the unescaped form that was displayed. 如果您单击链接,然后将URL复制并粘贴到记事本或其他内容中,则应获取实际使用的转义表单,而不是显示的未转义表单。

Uri.EscapeDataString, Uri.EscapeUriString, HttpUtility.UrlEncode and HttpUtility.UrlPathEncode are available to use in C# out of the box, they can not convert all the characters exactly the same way as JavaScript escape function does. Uri.EscapeDataString,Uri.EscapeUriString,HttpUtility.UrlEncode和HttpUtility.UrlPathEncode可直接在C#中使用,它们不能完全像JavaScript转义功能那样转换所有字符。

Solution: Use JScript.Net's own implementation. 解决方案:使用JScript.Net自己的实现。 Simply reference the Microsoft.JScript.dll and use the Microsoft.JScript.GlobalObject.escape() method to encode your url. 只需引用Microsoft.JScript.dll并使用Microsoft.JScript.GlobalObject.escape()方法对您的URL进行编码。

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

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