开发者

Why don't my Facebook share links work if they have spaces in them yet are encoded (asp.net mvc)?

Here's my code for my Facebook share link:

<a href="<%= HttpUtility.UrlPathEncode("http://www.facebook.com/sharer.php?u=http://www.apoads.com"+ Request.Url.PathAndQuery) %>" title="Share on Facebook" rel="nofollow" target="_blank"><img src="/Content/Img/Png/SocialIcons/facebook_16.png" width="16" height="16" alt="share on facebook" /></a>

the resulting url looks like this (copy and paste from view code within Firefox):

<a href="http://www.facebook.com/sharer.php开发者_C百科?u=http://www.apoads.com/en/Yokota/Biz/Show/Acrylic%20Nails%20for%20less" title="Share on Facebook" rel="nofollow" target="_blank"><img src="/Content/Img/Png/SocialIcons/facebook_16.png" width="16" height="16" alt="share on facebook" /></a>

Notice how the spaces in "Acrylic%20Nails%20for%20less" are represented by %20.

Yet, it appears Facebook totally strips out the %20, but also strips out the space all together! Since the name, with spaces, is how it is looked up in the database... my Facebook share link always reports a broken link.

Any way to make it keep the spaces?

Update I removed my code, added the AddThis code instead. The links generated by their service are encoded like this:

http%3A%2F%2Fwww.apoads.com%2Fen%2FYokota%2FBiz%2FShow%2FAcrylic%2520Nails%2520for%2520less

Is there a .net/c# utility to encode like this? or will I have to roll my own?


I would think that you'd want the link to be:

<a href='<%= String.Format("http://www.facebook.com/sharer.php?u={0}",
               HttpUtility.UrlPathEncode("http://www.apoads.com" + Request.Url.PathAndQuery)) %>' 
   title="Share on Facebook" 
   rel="nofollow" 
   target="_blank">
     <img src="/Content/Img/Png/SocialIcons/facebook_16.png" width="16" height="16" alt="share on facebook" />
</a>

Update From your update, it looks like it may be doubly encoded:

<a href='<%= String.Format("http://www.facebook.com/sharer.php?u={0}", 
               HttpUtility.UrlEncode(HttpUtility.UrlPathEncode("http://www.apoads.com"+ Request.Url.PathAndQuery))) %>' 
   title="Share on Facebook" 
   rel="nofollow" 
   target="_blank">
     <img src="/Content/Img/Png/SocialIcons/facebook_16.png" width="16" height="16" alt="share on facebook" />
</a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜