title: MVC HttpUtility.UrlEncode
body: <p>i am attempting to use HttpUtility.UrlEncode to encode strings that ultimately are used in URLs. </p>
  
  <p>example</p>
  
  <p>/string/http://www.google.com</p>
  
  <p>or</p>
  
  <p>/string/my test string</p>
  
  <p>where <a href="http://www.google.com" rel="nofollow">http://www.google.com</a> is a parameter passed to a controller.</p>
  
  <p>I have tried UrlEncode but it doesn't seem to work quite right</p>
  
  <p>my route looks like:</p>
  
  <pre><code>routes.MapRoute(
              "mStringView",
              "mString/{sText}",
              new { controller = "mString", action = "Index", sText = UrlParameter.Optional }
          ); 
  </code></pre>
  
  <p>The problem is the encoded bits are decoded it seems somewhere in the routing.. except things like "+" which replace " " are not decoded.. </p>
  
  <p>Understanding my case, where a UrlParameter can be any string, including URL's.. what is the best way to encode them before pushing them into my db, and then handling the decode knowing they will be passed to a controller as a parameter?</p>
  
  <p>thanks!</p>