Reputation: 37719
I have a .NET 4 WCF service running as an IIS website with ASP.NET compatibility mode. Once of the service methods accepts a string parameter and when there is a value which contains a '&' the ASP.NET pipeline raises a validation exception. I've assigned the following config settings:
<system.web>
<httpRuntime requestValidationMode="2.0"/>
<pages validateRequest="false"/>
</system.web>
And the error persists. The error occurs regardless of whether the input is encoded. I found a potential solution here which suggests providing a custom implementation of System.Web.Util.RequestValidator, however I was wondering whether there are alternatives that can be done with configuration settings only.
EDIT: I've also found this, however the proposed solution does not fix the problem.
Upvotes: 2
Views: 3039
Reputation: 37719
I've found the solution. I set the following configuration setting:
<system.web>
<httpRuntime requestPathInvalidCharacters=""/>
</system.web>
By default, and ampersand is an invalid path character.
Upvotes: 5
Reputation: 88064
Some links that may help:
summary: MS is stating that you should use %26 if the ampersand appears in the query string.
http://connect.microsoft.com/wcf/feedback/details/527185/wcf-rest-uritemplate-does-not-recognise-or-amp-ampersand-as-same-character
summary: poster is talking about encoding the & in the body of the WCF message using &
XmlReader chopping off whitespace after ampersand entity?
So, if it's in the query string encode it with %26. If it's in the body of the message encode as an html entity: &
Upvotes: 2