asp.netmonoubuntu-14.04fastcgi-mono-server

HTTP request validation Exception in ASP.NET Web Service on Ubuntu with Mono


First of all I am totally new to Linux Os and Mono as well.

I have taken all the steps from the following post to run my Web API service with Mono on Linux Ubuntu:

http://piotrwalat.net/running-asp-net-web-api-services-under-linux-and-os-x/

Now I am able to run my Web service on Ubuntu from localhost:5757, but when I execute a method, I get System.Web.HttpRequestValidationException:

A potentially dangerous Request.QueryString value was detected from the client 

This is my test method:

[WebMethod]
public string Test(string strXML)
{
    string strMessage = "";
    XmlDocument xdoc = new XmlDocument();
    try
    {
        xdoc.LoadXml(strXML);

        XmlNode xContent = xdoc.GetElementsByTagName("content")[0];
        strMessage = xContent.InnerText;
    }
    catch (Exception ex)
    {
        csGlobal.ErrorLog(ex.Message + " " + ex.StackTrace);
    }

    return strMessage;
}

This is the Input XML message that I want to test:

<data><content>some content</content></data>

It works perfect in IIS with Windows. But how can I make it work with Mono on Linux?

UPDATE:

.NET version is 3.5 and I added <pages validateRequest="false" /> in my web.config file, but still getting the same error.

What do you suggest me to do???


Solution

  • Change your Web API's .Net Framework version to 4.0 and include the following in your web.config:

    <httpRuntime requestValidationMode="2.0"/>
    

    This should help. But please note that in this case your API will be less protected and less stable for outer attacks.