我正在制作一个涉及登录服务器的应用程序,但是,发布数据需要一些编码。
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 的智能感知屏幕截图:
项目中引用的截图:
应用程序的输出:
unsafe text: <em>evil em tags within</em>
safe text: <em>evil em tags within</em>
关于vb.net - 如何在 Visual Studio (vb.net) 中使用 HtmlEncode(或 HtmlDecode)函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8597891/