I am getting this error "A potentially dangerous Request.Form value was detected from the client" when testing an input that is sent from the user to server via jQuery ajax. It only comes up when I intentionally put a single, double quote, html characters in the input ex "<s"c'o<>"
as my username. but still , I want to be able to gracefully encode and decode any bad input the user tries to enter.
here is client side jquery
var email = encodeURIComponent($('#loginEmail').val()); var password = encodeURIComponent($('#loginPassword').val()); $.ajax({ async: false, url: 'Account/CheckLogin', dataType: 'JSON', contentType: 'application/json', data: { email: email, password: password }, success: function (resp) { alert(resp.valid); if (resp.valid == "false") { isValid = false; $('.errorspan').show(); } } });
the controller code really isn't significant , since the error is thrown before it ever hits the first line's break point. It seems the Asp.net caught this trying to be passed as ajax before I get a chance to handle the code. My question is - why is this happening with the encodeUriComponent() ??
$.ajax({ async: false...
a cute little bunny dies somewhere maybe more...<
into%3c
, then jQuery is turning around and converting that into%253c
(25 is the code for the percent symbol). So when it finally makes it to the server, the<
won't be there for your code to look at -%3c
will be. So I'd say don't try to encode yourself, but rather use MattW's suggestion about turning off validation, and let the framework handle the encoding.