C# ASP.NET SQL SERVER

Double URL Encoding

Sometimes you know the answer but you still want to see it happen to make yourself happy.

Question: If you encode some text and then encode it again is it encoded inside encoded?
Answer: Yes
Question: What happens if you decode it twice as well?
Answer: You get back to the original unecoded text

Here is a snippet of text that demonstrates it using C# in .NET. You need to include the System.Web library.

            string stringWithAmp = "&";
            Console.WriteLine(stringWithAmp); // "&"
            stringWithAmp = HttpUtility.HtmlEncode(stringWithAmp);
            Console.WriteLine(stringWithAmp); // "&"
            stringWithAmp = HttpUtility.HtmlEncode(stringWithAmp);
            Console.WriteLine(stringWithAmp); // "&"
            stringWithAmp = HttpUtility.HtmlDecode(stringWithAmp);
            Console.WriteLine(stringWithAmp); // "&"
            stringWithAmp = HttpUtility.HtmlDecode(stringWithAmp);
            Console.WriteLine(stringWithAmp); // "&"
 

» Similar Posts

  1. Inheritance Question
  2. Powershell Grep
  3. How Stack Overflow is helping me

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback link for this post:
http://guyellisrocks.com/trackback.ashx?id=89

» Comments

    There are no comments. Kick things off by filling out the form below.

» Leave a Comment