How to use the HtmlEncode (or HtmlDecode) function in Visual Studio (vb.net)?

I am making an application that includes logging on the server, however the mail data needs some encoding.

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

However, since this is not an asp.net application, this does not work. How am I supposed to do this? I tried to search for Import, but no luck.

+6
source share
4 answers

If you add a link to System.Web in your project, you can use the following to encode the html string

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

MSDN Documentation for HttpUtility.HtmlEncode

Edit
Screenshot with intellisense showing HtmlEncode:
Screenshot of intellisense showing HtmlEncode

Screenshot in the project:
Screenshot of references in project

Exit the application:

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

System.web is not available in the NET 4.0 client profile ... I wonder why.

It cannot even be added as a link.

But the same can be done using:

System.Net.WebUtility.HtmlDecode

+5
source

You are using HttpUtility (first add a link to System.Web).

+1
source

In a Windows application, you can also use:

  System.Net.WebUtility.HtmlEncode 

providing a Framework version of version 4 or higher, see: [link] https://msdn.microsoft.com/en-us/library/ee388364(v=vs.110).aspx

0
source

Source: https://habr.com/ru/post/904278/


All Articles