Use the Theme Default Gravatar in BlogEngine.NET

by Erik Lane 3. November 2008 13:53

When I was setting up BE.NET I was glad to see it had support for Gravatars.  What I don’t like are the options available for people that don’t have one.  My option was to use MonsterID, Wavatar, or Identicon.  Those are pretty good but I wanted a more generic looking default…and less goofy looking.

So I went in and added an option to use the selected theme’s icon.

 

be_avatars

I added the option in the admin/pages/Settings.aspx page.  Saving it to the data store works without hitch since it just a name value pair.  Getting the theme’s icon to display requires a little bit of setup.

Theme Default Avatar

You need to add a noavatar.jpg image at the root of your theme’s folder.  Then update the BlogEngine.Core.Web.CommentViewBase.cs file:

   1: switch (BlogSettings.Instance.Avatar)
   2: {
   3:     case "identicon":
   4:         imgLink = gravatar + "identicon";
   5:         break;
   6:     case "wavatar":
   7:         imgLink = gravatar + "wavatar";
   8:         break;
   9:     case "monsterid":
  10:         imgLink = gravatar + "monsterid";
  11:         break;
  12:     default:
  13:         imgLink = gravatar + HttpUtility.UrlEncode(Utils.AbsoluteWebRoot + "themes/" + BlogSettings.Instance.Theme + "/noavatar.jpg");
  14:         break;
  15: }

Giddy Up!

Tags:
Comments are closed