Created
July 25, 2010 18:02
-
-
Save jasonyost/489733 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
public static class GravatarExtensions | |
{ | |
public static MvcHtmlString Gravatar(this HtmlHelper helper, string email, string username, int size) | |
{ | |
var baseURL = "http://www.gravatar.com/avatar/{0}?s={1}&d=identicon&r=PG"; | |
TagBuilder link = new TagBuilder("a"); | |
link.Attributes.Add("href", "/User/" + username); | |
TagBuilder img = new TagBuilder("img"); | |
img.Attributes.Add("src", string.Format(baseURL, Helpers.Functions.MD5Hash(email), size.ToString())); | |
img.Attributes.Add("alt", username); | |
img.Attributes.Add("title", username); | |
link.InnerHtml = img.ToString(); | |
return MvcHtmlString.Create(link.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gravatar extension for ASP.NET MVC 2