I am building a website where a user has profiles and profiles has profile pictures. The profile picture images need to maintained on my local storage. Is there any that I can use other services like Gravatar that will take care of profile images in my site. In this way I will not need to maintain user images in my site folder saving space etc. I will just ask users to link there Gravatar profile and use their profile images in my site's profile. I am developing my site in ASP.NET Please guide if there are any other services also that can help me to achieve this. Thanks in advance.

有帮助吗?

解决方案

The AjaxControlToolkit has Gravatar support built-in.

<ajaxToolkit:Gravatar runat="server"
    Email="test@superexpert.com"
    Size="200"
    Rating="R"
    DefaultImageBehavior="Identicon"
    DefaultImage="http://tinyurl.com/3bpsaac" />

Of course, this could be programmatically set as well...

Also, if your site provides OAuth login (like Facebook, LinkedIn, etc.) you could also reference those profile images as well using their APIs. Facebooks, for example, would look like:

<asp:Image ImageUrl="http://graph.facebook.com/[fbid]/picture?type=large"
    ToolTip="Facebook Avatar"
    Width="180"
    Height="180" />

replace [fbid] with their facebook id.

其他提示

You don't need to ask for their Gravatar and you don't need anything special to get it (besides the user's email address). From their docs:

All URLs on Gravatar are based on the use of the hashed value of an email address.... To ensure a consistent and accurate hash, the following steps should be taken to create a hash:

  1. Trim leading and trailing whitespace from an email address
  2. Force all characters to lower-case
  3. md5 hash the final string

So if you have <asp:Image ID="_grav" runat="server" /> on your page, in the very basic sense, it is just:

string email = "yourEmail.CoolSite.net "; //this would be the email you have on file for them
string hashedEmail = FormsAuthentication.HashPasswordForStoringInConfigFile(email.Trim().ToLower(), "MD5").ToLower();
_grav.ImageUrl = String.Format("http://www.gravatar.com/avatar/{0}", hashedEmail);

There are many other parameters you can use (size, default image if no gravatar exists, etc) that are just querystring additions to that ImageUrl. Read Image Requests.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top