2010-06-23 68 views
3

我有這樣一個WCF服務宣告操作:在嘗試調用URL Test/You%26Me無法將「%26」傳遞給WCF服務中的WebGet UriTemplate變量?

[WebGet(UriTemplate = "Test/{*testString}")] 
public String Test(String testString) 
{ 
    return testString; 
} 

但是,IIS會返回一個錯誤:

A potentially dangerous Request.Path value was detected from the client (&). 

我的目標是讓在URI的符號通過它的URL編碼:%26

通配符沒有幫助。有沒有什麼辦法可以在不禁用安全功能的情況下防止此錯誤?

回答

3

嘗試使用RequestPathInvalidCharacters配置屬性在Web.config中避免使用的字符如下:

<system.web> 
    <httpRuntime requestPathInvalidCharacters="<,>,*,:,\\" /> 
</system.web> 
+0

我忘了指定我沒有使用.NET 4.0,但 - 是有.NET 3.5的類似選項? – JoeGaggler 2010-06-23 16:38:29

+0

恐怕3.5中唯一的選擇是實現自定義的RequestValidator:http://msdn.microsoft.com/en-us/library/system.web.util.requestvalidator.aspx – 2010-06-23 17:13:27

+0

這很完美,謝謝! – JoeGaggler 2010-06-23 17:23:56