vb.net - 如何在 Visual Studio (vb.net) 中使用 HtmlEncode(或 HtmlDecode)函数?

标签 vb.net visual-studio html-encode

我正在制作一个涉及登录服务器的应用程序,但是,发布数据需要一些编码。

Dim strEncUsername As String = Server.HtmlEncode(Me.txtUsername.Text)

但是,由于这不是 ASP.NET 应用程序,因此这不起作用。我该怎么做呢?我尝试寻找 Imports 的东西,但没有真正的运气。

最佳答案

如果您将 System.Web 的引用添加到您的项目中,您可以使用以下内容对字符串进行 html 编码

Dim strEncUsername As String = System.Web.HttpUtility.HtmlEncode(Me.txtUsername.Text)

MSDN Documentation for HttpUtility.HtmlEncode

编辑
显示 HtmlEncode 的智能感知屏幕截图:
Screenshot of intellisense showing HtmlEncode

项目中引用的截图:
Screenshot of references in project

应用程序的输出:

unsafe text: <em>evil em tags within</em>
safe text: &lt;em&gt;evil em tags within&lt;/em&gt;

关于vb.net - 如何在 Visual Studio (vb.net) 中使用 HtmlEncode(或 HtmlDecode)函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8597891/

相关文章:

c++ - 在使用 VS2015 编译的应用程序中加载 VS2008 的调试可再发行组件失败

visual-studio-2010 - 尝试将 Visual Studio 连接到域外的测试 Controller 时出错

asp.net - 学习 jQuery 网站

javascript - 如何将附加到 mysql 引号的斜杠更改回其原始显示形式

vb.net - 如何将自定义文本文件添加到 Visual Studio 项目?

c# - 在 .net 控制台应用程序中显示消息框

java - 将字符串中的所有字符转换为不同的转义格式(Java)

php - 为什么这不会解码为 html 实体?

vb.net - 如何将格式函数从 VB 更新到 VB.NET

vb.net - SQL 注入(inject) : Why is the following code dangerous?