簡體   English   中英

將字符串轉換為轉義的html

[英]Convert string to escaped html

我是很多ASP.net MVC5功能的新手。 我想知道是否有一個庫會自動將轉義字符添加到旨在作為html輸出的C#字符串中? HTMLAgility Pack是否是我想要的? 還是有內置的東西適合您? 有人可以讓我知道我是否使用了正確的術語?

var fileContents = System.IO.File.ReadAllText(Server.MapPath("~/Static/email.txt"))

文件內容為:

<table width="600" cellpadding="0" cellspacing="0" style="background-color:black;">

該庫會將“ filecontents”轉換為:

 "<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\" style=\"background-color:black;\">\n"
System.Web.HttpUtility.HtmlEncode("<p>I am some html</p>");

將字符串輸出到html,可以嘗試使用HttpServerUtility.HtmlEncode

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM