Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Created August 8, 2013 12:42
Show Gist options
  • Save danielmackay/6184242 to your computer and use it in GitHub Desktop.
Save danielmackay/6184242 to your computer and use it in GitHub Desktop.
Social URL generator for Twiiter, Facebook, and Google+. #MVC.
public static class SocialUrl
{
public static string LocalUrl { get { return HttpContext.Current.Request.Url.AbsoluteUri; } }
public static string TwitterUrl(string postTitle = null, string twitterHandle = null)
{
var sb = new StringBuilder("https://twitter.com/intent/tweet?url=" + LocalUrl);
if (!string.IsNullOrWhiteSpace(postTitle))
sb.AppendFormat("&text={0}", postTitle);
if (!string.IsNullOrWhiteSpace(twitterHandle))
sb.AppendFormat("&via={0}", twitterHandle);
return sb.ToString();
}
public static string FacebookUrl()
{
return string.Format("https://facebook.com/sharer.php?u={0}", LocalUrl);
}
public static string GooglePlusUrl()
{
return string.Format("https://plus.google.com/share?url={0}", LocalUrl);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment