【发布时间】:2013-09-11 05:08:49
【问题描述】:
在 asp.net web api 中,我们可以使用操作过滤器 [ValidateModel] 进行日志记录: 如果由于在预期小数时发送字符串而导致绑定错误,则从对操作方法参数(例如汽车对象)的请求中记录 json 字符串会很有用。 在这些情况下,汽车对象为空。
问题 - 无法从请求对象访问已发布的 json 对象
//var car = actionContext.Request.Content.ReadAsStringAsync().Result;
或
//var car2 = actionContext.ControllerContext.Request.Content.ReadAsStringAsync().Result;
如何在 Action Filter 属性 ValidateModel 中获取 Car 参数的 json 字符串? 说方法:
//[ValidateModel]
//public HttpResponseMessage Post_Car(Car car) {
//}
【问题讨论】:
标签: asp.net-web-api