title: How to encode/decode product id in path in ASP.NET
body: <p>ASP.NET/Mono MVC4 shopping cart application users product codes as url names for awstats analytics like:</p>
  <p><a href="http://myshop.com/Store/Details/PRODUCT1" rel="nofollow noreferrer">http://myshop.com/Store/Details/PRODUCT1</a></p>
  <p>with default routing and controller</p>
  <pre><code>    public class StoreController : MyApp.ControllerBase
      {
  
          public ActionResult Details(string id)
          {
    ....
  </code></pre>
  <p>PRODUCT1 is product code.
  If product code contains / and other non-allowed characters in directory name, web server throws error.</p>
  <p>Product code should be human readable since analytics shows urls.
  How to encode product code to passed as directory name and decode it back in controller ?
  Product code should remain unique after encoding.</p>
  <p>Is there some built-in function in ASP.NET or some source code which implements this ?</p>
  <p>jquery, jquery ui, razor view engine is used.</p>
  <p><strong>Update</strong></p>
  <p>I tried recommendatiod in comment by creating Razor helper</p>
  <pre><code>@helper Details(string toode)
  {
      @Url.Action(&quot;Details&quot;, new { id = HttpUtility.UrlEncode(toode) });
  }
  </code></pre>
  <p>and then using</p>
  <pre><code>&lt;a href=&quot;@Details(someproduct)&quot;&gt;
  </code></pre>
  <p>This causes error:</p>
  <blockquote>
  <p>A potentially dangerous Request.Path value was detected from the client (%).
  GET /Store/Details/S%c3%9c%c3%9cTAJA HTTP/1.0</p>
  <p>% chareter is not allowed in url paths.
  So UrlEncode cannot used. How to encode/decode?</p>
  </blockquote>