コード例 #1
0
        public static HtmlString GravatarImage(this HtmlHelper htmlHelper, string emailAddress, GravatarOptions options = null)
        {
            if (options == null)
            {
                options = GravatarOptions.GetDefaults();
            }

            var imgTag = new TagBuilder("img");

            emailAddress = string.IsNullOrEmpty(emailAddress) ? string.Empty : emailAddress.Trim().ToLower();

            // <-- adding support for CSS
            if (!string.IsNullOrEmpty(options.CssClass))
            {
                imgTag.AddCssClass(options.CssClass);
            }
            // adding support for CSS  -->

            imgTag.Attributes.Add("src",
                                  string.Format("http://www.gravatar.com/avatar/{0}?s={1}{2}{3}",
                                                GetMd5Hash(emailAddress),
                                                options.Size,
                                                "&d=" + options.DefaultImageType,
                                                "&r=" + options.RatingLevel
                                                )
                                  );

            return(new HtmlString(imgTag.ToString(TagRenderMode.SelfClosing)));
        }
コード例 #2
0
        public static HtmlString GravatarImage(this HtmlHelper htmlHelper, string emailAddress, GravatarOptions options = null)
        {
            if (options == null)
                options = GravatarOptions.GetDefaults();

            var imgTag = new TagBuilder("img");

            emailAddress = string.IsNullOrEmpty(emailAddress) ? string.Empty : emailAddress.Trim().ToLower();

            // <-- adding support for CSS
            if (!string.IsNullOrEmpty(options.CssClass))
            {
                imgTag.AddCssClass(options.CssClass);
            }
            // adding support for CSS  -->

            imgTag.Attributes.Add("src",
                string.Format("http://www.gravatar.com/avatar/{0}?s={1}{2}{3}",
                    GetMd5Hash(emailAddress),
                    options.Size,
                    "&d=" + options.DefaultImageType,
                    "&r=" + options.RatingLevel
                    )
                );

            return new HtmlString(imgTag.ToString(TagRenderMode.SelfClosing));
        }