Rocky Singh
Rocky Singh

Reputation: 15420

Issue with HttpUtility.HtmlEncode with other language characters

I was trying to encode the HTML special characters like ', ", <,> etc with HttpUtility.HtmlEncode. But I noticed this is also encoding french characters like (é) to é and now é is getting displayed as it is on my HTML page. I don't want this I just want to encode ', ", <,> and few other characters.

Upvotes: 3

Views: 2316

Answers (2)

mkataja
mkataja

Reputation: 990

The various .NET text encoding functions are notorious for being badly documented and doing weird conversions. In some cases I've had better luck with the encoding functions in Microsoft Anti-XSS library, but not sure if this would work in your particular application.

Upvotes: 0

Nikola Radosavljević
Nikola Radosavljević

Reputation: 6911

Should those characters look differently? Why is it a problem if they are replaced? This is by design. You can take a look at this question to see longer discussion. Unless your users can't properly see text you are displaying, you shouldn't mess with this, for security/compatibility reasons.

HtmlUtility seems to encode several classes of characters, among which ISO-8859-1 character set If you still don't want a specific character to be encoded, you are forced to use string.Replace() for this purpose.

Upvotes: 1

Related Questions