WebServcies 调用方法异常:System.Web.HttpRequestValidationException: 从客户端中检测到有潜在危险的 Request.Form 值。

我在做WebServcies时,页面调试,报类了下面这样的错误信息:

System.Web.HttpRequestValidationException: 从客户端(checkXML="<?xml version="1.0" ...")中检测到有潜在危险的 Request.Form 值。
   在 System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)
   在 System.Web.HttpRequest.<>c__DisplayClass5.<ValidateHttpValueCollection>b__3(String key, String value)
   在 System.Web.HttpValueCollection.EnsureKeyValidated(String key)
   在 System.Web.HttpValueCollection.Get(String name)
   在 System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
   在 System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)
   在 System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
   在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

百度后,获得解决方案:

在Web.config配置文件中,向节点<httpRuntime> 里添加属性 requestValidationMode="2.0",即可解决问题。(其实,requestValidationMode的值只要是4.0以下都可以。具体原因,百度搜索validateRequest="false" 设置无效 有帖子回答这个问题,这里就不说明原因了。)

参考:http://www.cnblogs.com/vingi/articles/2478134.html

原文地址:https://www.cnblogs.com/lishidefengchen/p/4735930.html