2014-11-06 52 views
0

首先,我對Linux Os和Mono也是全新的。HTTP請求驗證在Ubuntu上使用Mono的ASP.NET Web服務中的異常

我已採取所有步驟從下面的帖子在Linux上運行Ubuntu的使用Mono我的Web API服務:

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

現在我能夠從localhost:5757運行在Ubuntu上我的Web服務,但當我執行的方法,我得到System.Web.HttpRequestValidationException

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

這是我的測試方法:

[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; 
} 

這是我想測試輸入的XML消息:

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

它可以完美運行在IIS與Windows。但是,我如何才能在Linux上使用Mono?

UPDATE:

.NET版本是3.5,我在我的web.config文件中添加<pages validateRequest="false" />,但仍得到相同的錯誤。

你建議我做什麼?

回答

1

更改Web API的版本的.NET Framework 4.0,包括您在web.config如下:

<httpRuntime requestValidationMode="2.0"/> 

這應該幫助。但請注意,在這種情況下,您的API將受到較少的保護,並且對於外部攻擊而言不太穩定。

+1

謝謝你。它解決了我的情況下的問題。 – 2014-11-11 04:45:12

相關問題