对字符串进行 HTML 编码并返回已编码的字符串。HTML-encodes a string and returns the encoded string.

public:

System::String ^ HtmlEncode(System::String ^ s);

public string HtmlEncode (string s);

member this.HtmlEncode : string -> string

Public Function HtmlEncode (s As String) As String

参数

要编码的文本字符串。The text string to encode.

返回

HTML 编码的文本。The HTML-encoded text.

示例

下面的示例演示如何对可能对不安全代码进行编码的值进行 HTML 编码。The following example shows how to HTML-encode a value that potentially codes unsafe code. 代码驻留在网页的代码隐藏文件中。The code resides in the code-behind file for a web page. 要编码的值在此示例中为硬编码,这只是为了简化示例,并显示可以进行 HTML 编码的值的类型。The value to encode is hard-coded in this example only to simplify the example and show the type of value you might HTML-encode. 通常,您需要对从用户或请求收到的值进行 HTML 编码。Typically, you would HTML-encode a value that you received from the user or the request. Result 引用 Literal 控件。Result refers to a Literal control.

public partial class _Default : Page

{

protected void Page_Load(object sender, EventArgs e)

{

Result.Text = Server.HtmlEncode("");

}

}Public Class _Default

Inherits Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

Result.Text = Server.HtmlEncode("")

End Sub

End Class

下面的示例与前面的示例类似,只不过它演示了如何对不在代码隐藏文件中的类中的值进行 HTML 编码。The next example is similar to the previous example except it shows how to HTML-encode a value from within a class that is not in the code-behind file.

public class SampleClass

{

public string GetEncodedText()

{

return HttpContext.Current.Server.HtmlEncode("");

}

}Public Class SampleClass

Public Function GetEncodedText() As String

Return HttpContext.Current.Server.HtmlEncode("")

End Function

End Class

注解

HTML 编码可确保文本在浏览器中正确显示,并且浏览器不会将其解释为 HTML 格式。HTML encoding makes sure that text is displayed correctly in the browser and not interpreted by the browser as HTML. 例如,如果文本字符串包含小于符号 () ,浏览器会将这些字符解释为 HTML 标记的左括号或右括号。For example, if a text string contains a less than sign (), the browser would interpret these characters as the opening or closing bracket of an HTML tag. 如果字符是 HTML 编码的,则将其转换为字符串 < 和 > ,这将导致浏览器显示小于号并正确地显示大于号。When the characters are HTML encoded, they are converted to the strings < and >, which causes the browser to display the less than sign and greater than sign correctly.

此方法是 HttpUtility.HtmlEncode 在运行时从 ASP.NET 应用程序访问方法的一种简便方法。This method is a convenient way to access the HttpUtility.HtmlEncode method at run time from an ASP.NET application. Internally, this method uses HttpUtility.HtmlEncode to encode strings.

在 ASP.NET 网页的代码隐藏文件中, HttpServerUtility 通过属性访问类的实例 Server 。In the code-behind file for an ASP.NET web page, access an instance of the HttpServerUtility class through the Server property. 在不在代码隐藏文件中的类中,使用 HttpContext.Current.Server 访问类的实例 HttpServerUtility 。In a class that is not in a code-behind file, use HttpContext.Current.Server to access an instance of the HttpServerUtility class.

在 web 应用程序之外,使用 WebUtility 类对值进行编码或解码。Outside of a web application, use the WebUtility class to encode or decode values.

适用于

html在线encode,HttpServerUtility相关推荐

  1. html在线encode,javascript另类方法实现htmlencode()与htmldecode()函数实例分析

    本文实例讲述了javascript另类方法实现htmlencode()与htmldecode()函数.分享给大家供大家参考,具体如下: 最常见的做法是采用正则表达式替换的方法,将特殊字符如 < ...

  2. Android通过Scheme协议打开APP界面

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/123238777 本文出自[赵彦军的博客] 文章目录 浏览器为什么能唤起App的页面 ...

  3. HTML Encode 编码在线转换工具

    HTML Encode 编码在线转换工具 请输入编/解码的进制(2, 8, 10, 16) 请输入编/解码的前缀("&#xH:16进制, &#D:10进制") 请输 ...

  4. 站长在线Python精讲:Python中字符串编码转换encode编码和decode解码详解

    欢迎你来到站长在线的站长学堂学习Python知识,本文学习的是<Python中字符串编码转换:encode编码和decode解码详解>.本知识点主要内容有:常用编码简介.使用encode( ...

  5. [Camera Drv]开video dynamic framerate,特定场景下video encode时会闪屏 - MTK物联网在线解答 - 技术论坛

    [Camera Drv]开video dynamic frame rate,特定场景下video encode时会闪屏 1. 开 video dynamic frame rate ,环境 BV 在 d ...

  6. html encode 在线,HttpUtility.HtmlEncode转义过多?

    在我们的MVC3 ASP.net项目中,HttpUtility.HtmlEncode方法似乎在逃避太多字符. 我们的网页是以UTF-8页面的形式提供的,但是这种方法仍然可以避免使用像ü或Yen字符这样 ...

  7. js在线压缩工具 支持Base62 encode 和 Shrink variables

    http://dean.edwards.name/packer/ 转载于:https://www.cnblogs.com/jsfans/archive/2011/07/04/2097849.html

  8. JavaScript Eval Encode/Decode JavaScript Eval 在线加密/解密, 编码/解码工具

    eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fr ...

  9. list对oracle结果集排序了_文章推荐系统系列之基于 FTRL模型的在线排序

    文章推荐系统系列: 1.推荐流程设计 2.同步业务数据 3.收集用户行为数据 4.构建离线文章画像 5.计算文章相似度 6.构建离线用户画像 7.构建离线用户和文章特征 8.基于模型的离线召回 9.基 ...

最新文章

  1. android view设置按钮颜色_Android 主题换肤技术方案分析
  2. 美国德州光伏装机可能拉低当地峰值电价
  3. 干货|靶场|工具|字典 分享
  4. 休息使用Jersey –包含JAXB,异常处理和客户端程序的完整教程
  5. 重新学习Ubuntu -- 截图软件的选择和安装
  6. element 输入框怎么加单位_抖音上的人声配音怎么制作?
  7. python编程技巧1002python编程技巧_总结Python编程中三条常用的技巧
  8. 地图学(何宗宜版)知识点整理
  9. Topshelf 打包部署Windows服务
  10. 【vue】微信sdk中接口和标签本地调试
  11. 共阳极管的代码_共阳极数码管显示
  12. 用Python批量把EXCEL表格中的数据提交到网页上
  13. python早读读后感_《学习Python》读后感摘抄
  14. HDU 6148 Valley Numer (数位DP)题解
  15. vue项目运行后页面一片空白
  16. WTG: Windows10企业版中安装Docker
  17. 在网站上的视频直播添加弹幕做法
  18. 如何下载mysql补丁_如何获取Oracle的补丁通告信息以及下载补丁
  19. 如何给自己制订一个“可实现的”新年目标?
  20. STM32HAL库微秒延时(μs)

热门文章

  1. 阿里巴巴开发手册笔记-----数据库篇
  2. 专门为码农朋友量身打造的笔记软件-Boostnote
  3. 网页打不开,提示【代理服务器拒绝连接】的解决办法
  4. 初探mapbox地图可视化实例,带你看看家附近有多少咖啡馆
  5. 朝题夕解——动态规划之整数划分模型
  6. linux 774是什么权限,Linux 权限位,权限值,权限管理
  7. CentOS 服务器性能查看
  8. java循环依赖问题怎么解决_Spring如何解决循环依赖的问题
  9. 端到端OCR算法:Real-time Arbitrarily-Shaped Text Spottingwith Point Gathering Network(PGNet)
  10. 服务器接收不到信号,Windows上的子进程未接收到信号(SIGTERM)