I'm writing an IHttpHandler implementation that will receive XML data sent through a regular HTTP POST from another website. Here's a prototype of the implementation:
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string s = context.Request.Form["input"]; // <== this throws HttpRequestValidationException
XmlDocument doc = new XmlDocument();
doc.LoadXml(s);
// ...
}
public bool IsReusable
{
get { return false; }
}
}
I'm testing the implementation with this simple page:
<body>
<form method="post" action="MPSConnector.Results.dsvc">
<textarea name="input"></textarea>
<input type="submit" value="Go!" />
</form>
</body>
The problem is that when i try to read the "input" value from the posted data, if it contains an xml string, all i get is a HttpRequestValidationException. I tried using
<pages validateRequest="false">
in web.config, and putting the validate="false" attribute in handler declaration in the httpHandles section, without results.
How can I read posted xml in my handler? (please note that i HAVE to use an IHttpHandler for this task).
EDIT: Framework version: 4.0, IIS 7.x
Thank you all! :)
As far as I know, you just need to encode that XML with entities.
I mean that < should be & lt; or > & gt;, and so on.
EDIT: I found that this is a duplicate of: How can Request Validation be disabled for HttpHandlers?
Try this!! :)