title: Why doesn't UriBuilder.query escaping (url encoding) the query string?
body: <p>The <code>UriBuilder.Query</code> property &quot;contains any query information included in the URI.&quot; <a href="http://msdn.microsoft.com/en-us/library/system.uribuilder.query(v=vs.110).aspx" rel="nofollow noreferrer">According to the docs</a>, &quot;the query information is escaped according to RFC 2396.&quot;</p>
  <p>Based on this, and since this property is writable, I assumed that when you set it, <code>System.UriBuilder</code> would parse your query string, and escape (url encode) according to RFC 2396. In particular, the { and } are not in the unreserved character set, and so <a href="https://www.rfc-editor.org/rfc/rfc2396.html#page-9" rel="nofollow noreferrer">they should be escaped according to page 9 of RFC 2396</a>. But, it appears that <code>System.UriBuilder</code> is not doing any escaping.</p>
  <p>Do I need to manually Server.URLEncode the params, or is there a way to get <code>System.UriBuilder</code> to handle the encoding?</p>
  <p>Here's my sample code. You can <a href="http://ideone.com/hWmd8l" rel="nofollow noreferrer">run this on ideone.com and see that, indeed, nothing is URL encoded</a>.</p>
  <pre><code>using System;
  
  public class Test
  {
      public static void Main()
      {
          var baseUrl = new System.Uri(&quot;http://www.bing.com&quot;);
          var builder = new System.UriBuilder(baseUrl);
          string name = &quot;param&quot;;
          string val = &quot;{'blah'}&quot;;
          builder.Query = name + &quot;=&quot; + val;
          
          // Try several different ouput methods; none will be URL encoded
          Console.WriteLine(builder.ToString());
          Console.WriteLine(builder.Uri.ToString());
          Console.WriteLine(builder.Query);
      }
  }
  </code></pre>