how to apply this HttpUtility Class in my code

신승민 1 Reputation point
2022-12-27T12:03:10.8+00:00

I use vb.net and .net 6
I want to apply this class and then use those mathods
how should I do?
bad english and beginner sorry,, T_T

Developer technologies | VB
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Castorix31 90,681 Reputation points
    2022-12-27T13:16:09.947+00:00

    In VB and Net 6, it works natively

    I tested for example :

     Dim UrlEncodedOutput = System.Web.HttpUtility.UrlEncode(your_string_to_encode)  
    
    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Tasadduq Burney 8,956 Reputation points MVP Volunteer Moderator
    2023-01-10T08:00:57.557+00:00

    Hello there!

    Welcome to Microsoft Forums!

    The System.Web.HttpUtility class provides several useful methods for encoding and decoding strings in a way that is safe for use in URLs and HTML. However, it's not included in the .NET 6 framework by default.

    You can use the System.Net.WebUtility class in place of System.Web.HttpUtility, which is included in .NET 6 and provides similar functionality.

    Here's an example of how you can use System.Net.WebUtility to encode a string for use in a URL:

    Dim originalString As String = "Hello World!"
    Dim encodedString As String = System.Net.WebUtility.UrlEncode(originalString)
    

    Console.WriteLine(encodedString) This will output Hello%20World%21

    Here's an example of how you can use System.Net.WebUtility to HTML encode a string to protect against XSS attack

    Dim originalString As String = "<script>alert('Hello World!')</script>"
    Dim encodedString As String = System.Net.WebUtility.HtmlEncode(originalString)
    

    Console.WriteLine(encodedString) This will output <script>alert('Hello World!')</script>

    You can also use System.Net.WebUtility class's methods such as UrlDecode and HtmlDecode to Decode the encoded string respectively.

    Note that you have to import System.Net namespace first in the top of your code, which you can do by adding the following line to your code:

    Imports System.Net
    

    I hope this helps you! Let me know if you have any other questions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.