0

I am creating an unbound function into an OData 18.2 v4 service in .net. The function is declared as follows:

WebApi Route Config:

modelBuilder
   .Function("MyFunction1")
   .ReturnsCollection<string>()
   .Parameter<string>("parameter1");
   
   

Controller:

[HttpGet]
[ODataRoute("MyFunction1(parameter1={value1})")]
public IHttpActionResult MyFunction1([FromODataUri] string value1)
{
    return Ok(MyFunction2(value1));
}



/Test/Default.MyFunction1(value1='HV / PD Testing')
  • how can I escape / Forward slash
Zoyeb Shaikh
  • 301
  • 1
  • 11
  • Try [double-escaping it](https://stackoverflow.com/a/40393737/134204) as `%252F`. The problem is that the slash is part of the URL's resource path itself, not a query parameter. – Panagiotis Kanavos Jul 05 '23 at 13:24
  • HTTP Error 404.11 - Not Found

    The request filtering module is configured to deny a request that contains a double escape sequence.

    – Zoyeb Shaikh Jul 05 '23 at 13:57
  • Just `%2F` ? From [the specs](https://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc453752335) `http://host/service/Categories('Smartphone%2FTablet')` should be valid while `http://host/service/Categories('Smartphone/Tablet')` isn't. In the past double-escaping was needed because Web API itself translated `%2F` as a slash, before the query got to OData – Panagiotis Kanavos Jul 05 '23 at 14:03
  • I tried %2F but it still not working /Test/Default.MyFunction1(value1='HV %2F PD Testing') I am still getting an error – Zoyeb Shaikh Jul 05 '23 at 14:06
  • %2F is just working fine with odata filter query like this -> Test/?$filter=Status eq 1 and DocNo eq 'AB%2F00096' but not with unbound function – Zoyeb Shaikh Jul 05 '23 at 14:09
  • What error? The actual error matters. Failing to find a match because of extra whitespace isn't the same as the server rejecting the URL itself. Which OData version are you using? ASP.NET Core or ASP.NET Framework? – Panagiotis Kanavos Jul 05 '23 at 14:09
  • The latest [Microsoft.AspNetCore.OData](https://www.nuget.org/packages/Microsoft.AspNetCore.OData/) version is 8.2, not 18.2. Which one are you using? There may a related issue in the Github repo of whatever library you use – Panagiotis Kanavos Jul 05 '23 at 14:13
  • I am getting Server Error in '/' Application.

    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4494.0
    – Zoyeb Shaikh Jul 05 '23 at 14:14
  • tried this configuration but it did not help config.Formatters.JsonFormatter.SerializerSettings.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii; – Zoyeb Shaikh Jul 05 '23 at 14:19
  • What packages and versions are you using? `ASP.NET Version:4.8.4494.0` means you're using ASP.NET Framework, not Core, so you're using an older OData version. Which one? – Panagiotis Kanavos Jul 05 '23 at 14:20
  • Microsoft.Data.OData 5.8.3.0 , ASP.NET Version:4.8.4494.0 – Zoyeb Shaikh Jul 05 '23 at 14:22
  • Do you *have* to use .NET Framework? All new development, both for the web infrastructure and and OData, goes into ASP.NET Core and .NET Core. The problems you have may already be fixed. – Panagiotis Kanavos Jul 05 '23 at 14:22
  • [Microsoft.Data.OData is deprecated since 2021](https://www.nuget.org/packages/Microsoft.Data.OData) due to critical bugs. You shouldn't use it. – Panagiotis Kanavos Jul 05 '23 at 14:24
  • For .NET Framework the correct package is [Microsoft.AspNet.OData](https://www.nuget.org/packages/Microsoft.AspNet.OData/) currently at 7.7.0, released in June 2023 – Panagiotis Kanavos Jul 05 '23 at 14:26
  • sure I am going to discuss with my manager about you have told me but currently I am still stuck with my problem – Zoyeb Shaikh Jul 05 '23 at 14:26
  • 1
    There's a related GH issue in the [OData.net](https://github.com/OData/odata.net/issues/735) site. Seems this was fixed in the past allowing `%2F` to work but broke later and may still exist in ASP.NET Core. One of the workarounds suggested is to use a [parameter alias](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_ParameterAliases), eg `.MyFunction1(value1=@value)?@value='HV %2F PD Testing'`. Didn't know that's possible – Panagiotis Kanavos Jul 05 '23 at 14:59
  • http://server/Sales.GetEmployeesByManager(ManagerID=@p1)?@p1=3 , I followed your instructions and thanks it is working fine but how can I pass Multiple parameter i have Id and Name passing to Unbound function – Zoyeb Shaikh Jul 06 '23 at 10:04

0 Answers0