Pages

Tuesday, March 22, 2011

Gravatar Helpers | ASP.NET MVC

Update: 2011-04-26 Changed the methods from returning string to returning MvcHtmlString (silly me) and created a few more overloads to assign a title attribute.

Was looking for a helper that I'd seen previously. I still haven't found it, but noticed this post with Gravatar helpers.

I've adjusted it in the following ways:

The code didn't trim or lowercase the email address before hashing, so I changed that

I added an overload which takes an enum for selecting the default image.

The Url for the default image was not being Url encoded. This is fine if you are using one of the defaults that they provide, but might not work if you pass a Url to an image in.

There are several more overloads

Generally made more of a mess :oD

Some of these changed just help to ensure that there are no problems when getting the Gravatar, some are just niceties for me which are probably a little clearer to read, but not really necessary considering that you would generally call these a total of maybe 1 or 2 places in an application.

Tweets

Twitter Updates

Opinions expressed in this blog are my own personal opinions and do not represent the opinions of my employer in any way. Code and information in this blog should be used at your own risk. I take no responsibility for any problems that may arise by anyone using code or information in this blog. Again, you may only use the code or information on this blog at your own risk.