PHP的htmlspecialcharacters在.NET等价?PHP、htmlspecialcharacters、NET

2023-09-03 15:42:26 作者:小妞、来啵个

PHP有一个很大的函数调用 htmlspecialcharacters()在那里你传递一个字符串,并将其替换所有的HTML的特殊字符与他们的安全等同,它的几乎的用于消毒的输入提供一站式服务。很不错吧?

PHP has a great function called htmlspecialcharacters() where you pass it a string and it replaces all of HTML's special characters with their safe equivalents, it's almost a one stop shop for sanitizing input. Very nice right?

那么有没有在任何.NET库的等效?

Well is there an equivalent in any of the .NET libraries?

如果没有,任何人都可以链接到任何code样品或库这样做呢?

If not, can anyone link to any code samples or libraries that do this well?

推荐答案

试试这个。

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