Search code examples
c#asp.nethtml-encode

ASP.NET Server.HtmlEncode Won't Encode €


I know that the EURO currency symbol (€) is encoded as € in HTML, but the System.Web.HttpUtility.HtmlEncode("€") doesn't encode it at all. Does anyone know why that is?


Solution

  • HttpUtility.HtmlEncode only encodes characters that are "reserved" in HTML. For that list, see the first table on this page: http://www.w3schools.com/tags/ref_entities.asp.

    In other words, only those characters that can conflict with the basic structre of HTML (e.g. <, >, ", etc). No other characters must be encoded as long as the encoding of the transmitted bytes is identified correctly (e.g. by using and declaring UTF-8).