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.

3
  • That's just URL encoding. '%3F' is '?', '%5C' is '\' and '%3D' is '=' Commented Apr 5, 2019 at 14:57
  • how do I remove it. Commented Apr 5, 2019 at 14:59
  • see stackoverflow.com/a/29993210/4033690 Commented Apr 5, 2019 at 15:06

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.