更新时间:2022-11-22 11:58:44
As noted by MatthewG above, the answer had already been posted to html entity encode text only, not html tag - the solution is to use HTMLAgilityPack and pass the html text or node to the method entitize - this encodes only the page content and not the tags.
using HtmlAgilityPack;
html = HtmlEntity.Entitize(html);