![](/img/trans.png)
[英]potentially dangerous request.form value was detected from the client innerhtml
[英]A potentially dangerous Request.Form value was detected from the client, encoding help please
所以我试图将一个字符串作为参数通过Js中的Post提交给asp.net服务,但是我遇到了一些困难。 在声明之前,我无权访问服务器,也无法触摸验证,我严格从外部客户端进行访问。 我得到这个回应
System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (message="...t;img src='http://192.168.1...").
at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)
at System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection)
at System.Web.HttpRequest.get_Form()
at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
我发送的消息是:
xcvxzcvzxcvxcvzxcv< br /><img src='http://192.168.1.1:82/UserUploads/Images/65968/20130122020024996.jpg' alt='User Image' />
我使用以下代码进行编码:
htmlEncode: function(str) {
str = str.replace(/&/g, '&');
str = str.replace(/'/g, ''');
str = str.replace(/"/g, """);
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
return str;
},
产生:
xcvxzcvzxcvxcvzxcv< br /><img src='http://192.168.1.1:82/UserUploads/Images/65968/20130122020802027.jpg' alt='User Image' />
我已经通过了多个验证器,并检查了我的编码,但无法确定是什么导致了问题。 我唯一的猜测是http://引起了JavaScript错误中所示的问题,但我不确定。 任何帮助或见识将不胜感激。
问题是'的编码。 根据user409762,&#的组合在asp.net中被标记为危险。
所以现在我的编码看起来像这样,并且工作正常。
htmlEncode: function(str) {
str = str.replace(/&/g, '&');
str = str.replace(/"/g, """);
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
return str;
},
使用Jquery,您可以像该link一样执行编码和解码。
function htmlEncode(value) {
return $('<div/>').text(value).html();
}
function htmlDecode(value) {
return $('<div/>').html(value).text();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.