Server.UrlEncode apostrophe(') in Firefox
So I have a Hyperlink called lnkTwitter:
And I'm trying to set the url in the code behind:
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开发者_JAVA技巧 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".
For some reason, this only happens in Firefox; in IE, I am taken to the correct 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. While this can be confusing it should not cause your code or the sites you link to (twitter, in this case) any problems.
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.
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.
Solution: Use JScript.Net's own implementation. Simply reference the Microsoft.JScript.dll and use the Microsoft.JScript.GlobalObject.escape() method to encode your url.
精彩评论