I am using AntiXss library 4.0 for encoding text before displaying on the asp page.
<asp:Label Text="text" runat="server" ID="lblTest" />
<asp:ListBox runat="server" ID="lsbTest">
</asp:ListBox>
This is the asp code. In the PageLoad I am writing
lblTest.Text = Encoder.HtmlEncode("test & test");
lsbTest.Items.Add(new ListItem(Encoder.HtmlEncode("test & test"), Encoder.HtmlEncode("test & test")));
Here, when the text in the label is rendered, it shows & as &, but in the case of Listbox, & is rendered as &. But, I want this to be rendered as & even in listbox.
How to do this?
Thanks,
Ashwani
The items in a
ListItemare automatically encoded for you. If you have configured the AntiXSS library as defaultHttpEncoder, you wont have to encode it manually. If you didn't configure it, ASP.NET will use the default (less secure) encoding.To configure it, read this article.