views:

66

answers:

1

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?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?

+1  A: 

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>
Forgotten Semicolon
Thanks for the quick response. I just tried it out, it does exactly the same thing I described. Looks like Facebook strips out the spaces. ;(
Chad
Maybe try plus-signs instead of %20.
Forgotten Semicolon
Same issue... looks like they really do strip spaces when using the share url. The like button, which uses the exact same url, works fine. ;(
Chad
I updated my question, it looks like I need to encode differently.
Chad
Yup, that was it. Thanks!
Chad