Wednesday, November 28, 2007

.Net documentation missing

Just figured out that the HtmlWriter.AddAttribute() does an encoding based on the HtmlTextWriterAttribute enum you give as the first parameter. How? By inspecting the source code of Mono. With this knowledge I searched MSDN, but couldn't find a thing.

The bottomline: don't use a writer.AddAttribute(HtmlTextWriterAttribute.Href,
HttpUtility.HtmlAttributeEncode(url));
because then you're encoding twice.

The list of attributes which enode is:

HtmlTextWriterAttribute.Accesskey;
HtmlTextWriterAttribute.Alt;
HtmlTextWriterAttribute.Background;
HtmlTextWriterAttribute.Class;
HtmlTextWriterAttribute.Href;
HtmlTextWriterAttribute.Onchange;
HtmlTextWriterAttribute.Onclick;
HtmlTextWriterAttribute.Src;
HtmlTextWriterAttribute.Title;
HtmlTextWriterAttribute.Value;

No comments: