3
votes

I have an odata function called GetForPeriod defined as:

        var getForPeriod =
            builder.EntityType<EventModel>()
                .Collection
                .Function("GetForPeriod")
                .ReturnsCollection<EventModelSummary>();
        getForPeriod.Parameter<DateTimeOffset>("from");
        getForPeriod.Parameter<DateTimeOffset>("to");

So to get results from the function, I need to call:

http://localhost:17257/odata/Events/Default.GetForPeriod(from=2015-12-27T00:00:00-06:00,to=2016-02-06T00:00:00-06:00)

But I keep getting an error stating:

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

The problem is the dates, as if I do http://localhost:17257/odata/Events/Default.GetForPeriod(from=null,to=null) I get an error stating that it can't convert null to a DateTimeOffset (which makes sense).

I tried replacing the colon (:) in the from and two values to %3A, but I still get the same dangerous path error.

Interesting enough, if I call the read path for events with a date filter it works fine. 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

How am I supposed to call an OData function which takes a datetime offset for a parameter?

3

3 Answers

3
votes

Would you please try the function parameter alias?

From OData spec:

A parameter alias can be used in place of an inline parameter to a function call. The value for the alias is specified as a separate query option using the name of the parameter alias.

Example 76: invoke a Sales.EmployeesByManager function via the function import EmployeesByManager, passing 3 for the ManagerID parameter

http://host/service/EmployeesByManager(ManagerID=@p1)?@p1=3

The same issue is tracked on https://github.com/OData/WebApi/issues/204

Thanks.

1
votes

Add this to your web.config file.

<system.web>
    <httpRuntime requestPathInvalidCharacters="%" />
</system.web>
0
votes

I had to create a web.config file with the following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering allowDoubleEscaping="true"/>
    </security>
  </system.webServer>
</configuration>