开发者

Microsoft.Web.Helpers Gravatar error in generated URL

I'm using the Grav开发者_开发技巧atar 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?


<%: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


In code (say in the controller action... and not in the *.aspx or *.cshtml markup), when I do this:

var avatarUrl = Gravatar.GetUrl("someone@somewhere.com", defaultImage: "identicon");

This will return the following string:

http://www.gravatar.com/avatar/923d10bc97028030e8e67e7db62658d1?s=80&amp;d=identicon

Note the encoded ampersand (&amp;) where there shouldn't be any encoding. I think this is not working as intended. The reason it matters, is because instead of getting the identicon (or gravatar) that we want, we get the default gravatar logo, which we dont want (the whole point of the identicon fallback). Remember, this was done from the controller, vice the view markup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜