title: Disable Url Encoding in ASP.NET MVC
body: <p>In my ASP.NET MVC application, there is url for example:</p>
  
  <pre><code>&lt;img src="/photo/22316/byt+3%2b1+n.s+(16)/600x400"&gt;
  </code></pre>
  
  <p>which is mapped to action</p>
  
  <pre><code>public void Photo(string sid, string name, int? width, int? height)
  {     
    //read image, resize and return
  }
  </code></pre>
  
  <p>The problem is that the string </p>
  
  <pre><code>byt+3%2b1+n.s+(16)
  </code></pre>
  
  <p>is automatically decoded by ASP.NET MVC as </p>
  
  <pre><code>byt+3+1+n.s+(9)
  </code></pre>
  
  <p>and the image cannot be found, because the name of file is</p>
  
  <pre><code>byt 3+1+n.s (9).jpg
  </code></pre>
  
  <p>I cannot even replace + for space, because only some of plus marks were created by encoding. I need to disable the encoding of parameter of this particular action to solve this issue.</p>
  
  <p>I know that it is better to generate some IDs, but it is late know to change id, I need to preserve the url of images because of compatibility issues and google image search.</p>
  
  <p>The Url routing is:</p>
  
  <pre><code>routes.MapRoute(
  null,
  "photo/{sid}/{name}/{width}x{height}", // URL
  new { controller = "Nemovitost", action = "Foto" }
  );
  </code></pre>
  
  <p>In watch there is:</p>
  
  <pre><code>HttpContext.Request.Url = {http://localhost:31182/photo/22316/byt+3+1+n.s+(9)/600x400}
  </code></pre>
  
  <p>But in fiddler I can see:</p>
  
  <pre><code>http://localhost:31182/photo/22316/byt+3%2b1+n.s+(9)/600x400
  </code></pre>
  
  <p>The razor template (simplified):</p>
  
  <pre><code>public static string BuildImageUrl(int realtyId, string filename, int w, int h)
  {
      filename = Path.GetFileNameWithoutExtension(filename);
  
      return string.Format("/photo/{0}/{1}/{2}x{3}", realtyId, HttpUtility.UrlEncode(filename), w, h).ToLower();
  }
  
  var rsImgF = "&lt;img src=\"{0}\"&gt;";
  
  ....                       
  
  var rsImg = string.Format(rsImgF, ....,
      BuildImageUrl(Model.RealtyId, img.Filename, 600, 400));
  
  @Html.Raw(rsImg);
  </code></pre>