【发布时间】:2016-01-12 23:02:00
【问题描述】:
我有一个名为 GetForPeriod 的 odata 函数定义为:
var getForPeriod =
builder.EntityType<EventModel>()
.Collection
.Function("GetForPeriod")
.ReturnsCollection<EventModelSummary>();
getForPeriod.Parameter<DateTimeOffset>("from");
getForPeriod.Parameter<DateTimeOffset>("to");
所以要从函数中获取结果,我需要调用:
http://localhost:17257/odata/Events/Default.GetForPeriod(from=2015-12-27T00:00:00-06:00,to=2016-02-06T00:00:00-06:00)
但我不断收到一条错误消息:
从客户端 (:) 检测到有潜在危险的 Request.Path 值。
问题是日期,好像我这样做了
http://localhost:17257/odata/Events/Default.GetForPeriod(from=null,to=null)
我收到一条错误消息,指出它无法将 null 转换为 DateTimeOffset(这是有道理的)。
我尝试将 from 中的冒号 (:) 和两个值替换为 %3A,但仍然遇到相同的危险路径错误。
有趣的是,如果我使用日期过滤器调用事件的读取路径,它可以正常工作。
http://localhost:17257/odata/Events?$filter=ScheduledDate%20ge%202015-12-27T00:00:00-06:00%20and%20ScheduledDate%20le%202016-02-06T00:00:00-06:00
我应该如何调用一个 OData 函数,该函数需要一个参数的日期时间偏移量?
【问题讨论】:
标签: .net function odata asp.net-web-api2 datetimeoffset