PHPs htmlspecialcharacters equivalent in .NET? PHPs htmlspecialcharacters equivalent in .NET? asp.net asp.net

PHPs htmlspecialcharacters equivalent in .NET?


Try this.

var encodedHtml = HttpContext.Current.Server.HtmlEncode(...);


Don't know if there's an exact replacement, but there is a method HtmlUtility.HtmlEncode that replaces special characters with their HTML equivalents. A close cousin is HtmlUtility.UrlEncode for rendering URL's. You could also use validator controls like RegularExpressionValidator, RangeValidator, and System.Text.RegularExpression.Regex to make sure you're getting what you want.