3

I am making a Restful api using OData, and for some reasons I want to force the expand filtering inside the middleware.

So if the clients sends in

http://localhost:52973/odata/customers

The Middleware should automatically change it into

http://localhost:52973/odata/customers?$expand=Contact,Address

In order to do this I've made a simple if statement inside my middleware

if (ctx.Request.Path.Value.Contains("customers") && !ctx.Request.QueryString.Value.Contains("?$expand"))
{
    string uri = @"?$expand=";
    ctx.Request.QueryString = ctx.Request.QueryString.Add(uri, "Contact,Address");
}

Unfortunately, it keeps generating the following: {?%3F%5C$expand%5C%3D=Contact,Address}

I've tried adding backslashes inside the uri string, but that didn't solve it.

Falcon
  • 837
  • 1
  • 9
  • 28

1 Answers1

0

I would assume that it is url-encoding ("escaping") the '$' character to make it safer, so I would not approach this problem from that angle. I would modify your consumers of this request to url-decode the request, which may be automatically done. See QueryString.ToUriComponent, and also the QueryString.ToString() method too.

samhuk
  • 109
  • 1
  • 8