I have an ASP.NET Web Service (asmx) function with string parameters. The built in request validation should catch HTML tags and it works when using the auto generated localhost test page or with jQuery's ajax/post if dataType is not set to json (ValidateRequest="true").
With dataType:"json"
HttpRequestValidationException
is not triggered:
$.ajax({
type: "POST",
url: "/my.asmx/SetName",
data: '{"name":"' + $("#name").val() + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false
});
If I remove contentType
and dataType
I get the expected HttpRequestValidationException
.
This leaves my ws vulnerable. Unfortunately WCF is not an option.