Search code examples
asp.net-mvcgravatar

Microsoft.Web.Helpers Gravatar error in generated URL


I'm using the Gravatar helper class from Microsoft.Web.Helpers like so

<%: Gravatar.GetHtml("me@domain.com", 80, "identicon") %>

which produces in the source

<img src="http://www.gravatar.com/avatar/0ff2e377be7d73b15f0b48022a755717?s=80&amp;d=identicon" alt="gravatar" />

The image URL does work but shouldn't it be &d=identicon and not &amp;d=identicon? It appears to have encoded the ampersand. This is also the same when using Gravatar.GetUrl()

How can I stop it encoding the ampersand without rewriting my own version?


Solution

  • <%:Gravatar.GetHtml("me@domain.com", 80, "identicon") %>
    

    Your telling it to encode the output, ":" is short hand for this. If you do not want to encode the output, do this

    <%=Gravatar.GetHtml("me@domain.com", 80, "identicon") %>
    

    As far as I am aware ":" is shorthand for outputting via Html.Encode()

    =========Edit

    What the Helper is doing is correct, it should be encoding the ampersand, more info at the link below

    XHTML and & (Ampersand) encoding