换掉BlogEngine.NET万恶的头像

BlogEngine.NET中的评论头像,预设都是从www.gravatar.com中下载的。每个人(包括作者自己)的头像一开始都是随机,之后只要email地址保持一样,头像都不会改变,而BlogEngine.NET不允许更改头像的来源,只能选择显不显示头像。这种做法当然是不得人心的。好,让我们来改掉这个头像吧。

打开BlogEngine.NET solution,在BlogEngine.Core project中找到BlogEngine.Core.Web.Controls.CommentViewBase,打开源文件:

[code:c#]

protected string Gravatar(int size) 
{
  if (BlogSettings.Instance.Avatar == "none")
    return null;
  //added by Alex to display author's picture
  AuthorProfile profile = AuthorProfile.GetProfile(Comment.Author);
  if (profile != null)
  {
    return "<img src="\" alt="" />";
  }
  // other codes...
}

[/code]

加上add by Alex的代码,其他不变。以上代码是检查发评论的人是不是系统登记的作者,如果是的话就根据该作者的照片路径来显示头像。当然,如果你只是访客的话那就没办法咯,只能用预设的随机头像了,哈哈。

编译以上project,在BlogEngine.Core/bin/Debug中找到新建的三个dll,pdb和xml文件。将他们拷贝到 <你的网站>/bin/ 下面取代原有的。打开网页,大功告成了吧。