Monday, 28 January 2013 13:56

how to get Gravatar image in asp.net application

Written by 
Rate this item
(0 votes)

Gravatar.com is used to store one's avatar image according to email.
then if you comment in any application using your that email address
where gravatar image has been programmed then your avatar image will
be displayed in the application.

implementing gravatar.com based image in asp.net is not difficult
if you know how to do that by following way.many programmers at
first find it difficult to implement.one may want to display
default image if gravatar image is not available for the user
email address.let's do it -

public string GetGravatarFullUrl(int size, string emailid)
{
//System.Threading.Thread.Sleep(10000);
string email = emailid;
string hash = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(email.Trim(), "MD5");
hash = hash.Trim().ToLower();
string gravatarUrl = string.Format("http://www.gravatar.com/avatar.php?gravatar_id={0}&rating=G&size=size", hash);
return gravatarUrl;
}

when email supplied as a parameter to the above method, it will return gravatar image
url.but by the following way it is confirmed that local default image will be
displayed if gravatar image not available -

string primaryUrl=GetGravatarFullUrl(60, "This email address is being protected from spambots. You need JavaScript enabled to view it.")

string finalUrl= primaryUrl + "&default=http://domainname.com/images/default_user.png";

Read 3005 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.