.net中如何使用HtmlEncode
来源:百度知道 编辑:UC知道 时间:2024/06/18 22:30:29
.net中如何使用HtmlEncode
导入什么命名空间
怎么使用
在线等
编译器错误信息: CS0120: 非静态的字段、方法或属性“System.Web.HttpServerUtility.HtmlEncode(string)”要求对象引用
导入什么命名空间
怎么使用
在线等
编译器错误信息: CS0120: 非静态的字段、方法或属性“System.Web.HttpServerUtility.HtmlEncode(string)”要求对象引用
命名空间:System.Web.HttpContext.Current.Server.HtmlEncode(string);
使用Demo:
public void Page_Load(object sender, EventArgs e)
{
string strHtml = "<h1>是标题标记</h1>";
string strHtmlEncode = Server.HtmlEncode(strHtml); //编码
string strHtmlDecode = Server.HtmlDecode(strHtmlEncode);//解码
Response.Write(strHtml + "<br>");
Response.Write(strHtmlEncode + "<br>");
Response.Write(strHtmlDecode + "<br>");
}
System.Web.HttpContext.Current.Server.HtmlEncode(string);
System.Web.HttpContext.Current.Server.HtmlEncode(string s);
System.Web.HttpServerUtility.HtmlEncode
需要引用System.Web。如果你的项目是Web项目的话,默认已经引用了他。