当我调用我的网络服务女巫时,我得到了两个参数:
从客户端 (&) 检测到具有潜在危险的 Request.Path 值。
路由配置:
config.Routes.MapHttpRoute(
name: "PropertiesSearch",
routeTemplate: "api/property/Search/{category}/{query}",
defaults: new { controller = "Property", action = "Search", category = "common", query = string.Empty }
);
Controller 方法:
[HttpGet]
public SearchResult Search(string category, string query)
{
}
当我调用 api 时:
/api/property/search/homes/areaId%3D20339%26areaId%3D20015
从客户端 (&) 检测到具有潜在危险的 Request.Path 值。
这样做:
/api/property/search/homes/?query=areaId%3D20339%26areaId%3D20015
工作正常。
如何解决路由解码问题?
最佳答案
斯科特·汉塞尔曼 blogged about this .您可能需要检查 requestPathInvalidCharacters
<httpRuntime>
的属性(property)web.config 中的节点。
就我个人而言,我会避免在 uri 部分中使用此类字符,而只是将这些值作为查询字符串参数。
关于c# - 当 url 包含编码的符号时,MVC WEB API 路由失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14359305/