Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC Double Encoding MvcHtmlString
    primarykey
    data
    text
    <p><em>Caveat: I have an MVC site as an area in a .Net WebForms site. I'm explaining that in advance in the case that it sheds light on my issue.</em> </p> <p>Now the issue I am having is that I am routing values that could contain special characters like an <code>apostrophe</code> (single quote). If i do not encode the value it routes properly however, my <code>Kendo MVC Grid</code> creates a invalid template when using the unencoded single quote as a filter.</p> <pre><code>http://{base}/{area}/{controller}/{view}?customerName=Justin's%20Instance - Throws Invalid Template Error http://{base}/{area}/{controller}/{view}?customerName=Justin&amp;#39;s%20Instance - No Error </code></pre> <p>So I thought the easiest solution was to properly encode my querystring parameter prior to passing it as a route value. That resulted in a double encoding situation. Then I found out about <code>MvcHtmlString.Create</code> which is specifically designed to tell the routing system not to re-encode the string value. However, it is still double encoding. </p> <pre><code>var customerNameEncoded = MvcHtmlString.Create(HttpUtility.HtmlEncode(model.Name)); var routeResult = RedirectToAction("ManageCustomer", new { customerName = customerNameEncoded }); return routeResult; </code></pre> <p>This is the Url that is created: </p> <pre><code>http://{base/{area}/{controller}/{view}?customerName=Justin%26%2339%3Bs%20Instance </code></pre> <p>As you can see the &#39; is being encoded again. This is throwing the following error. </p> <pre><code>&gt; System.Web.HttpRequestValidationException A potentially dangerous &gt; Request.QueryString value was detected from the client &gt; (customerName="Justin&amp;#39;s Instance"). </code></pre> <p>The <code>web.config</code> for the MVC area has the following tag: <code>validateRequest="false"</code></p> <p>The <code>web.config</code> for the overall website has the following: <code>httpRuntime requestValidationMode="2.0"</code></p> <p>Any ideas as to why this string is being double encoded and how to stop it from doing so?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload