Can't pass in “%26” to a WebGet UriTemplate variable in a WCF service?

亡梦爱人 提交于 2021-02-19 04:19:41

问题


I have a WCF service with this declared operation:

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

However when attempting to invoke the URL Test/You%26Me, IIS returns an error:

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

My goal is to allow an ampersand in the URI via its URL-Encoding: %26

The wildcard did not help. Is there any way to prevent this error without disabling security features?


回答1:


Try using RequestPathInvalidCharacters configuration property in Web.config avoiding used characters as follows:

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


来源:https://stackoverflow.com/questions/3102897/cant-pass-in-26-to-a-webget-uritemplate-variable-in-a-wcf-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!