开发者

How to disable ASP.NET request validation for WCF service?

开发者 https://www.devze.com 2023-03-19 18:42 出处:网络
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开发者_StackOverflow which contai

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开发者_StackOverflow 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.


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.


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 &amp;
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: &amp;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号