我正在使用OData制作一个Restful API,由于某些原因,我想在中间件内强制进行扩展过滤。因此,如果客户端发送以下内容:
中间件应自动将其更改为:
为了实现这一点,我在我的中间件内做了一个简单的if语句。http://localhost:52973/odata/customers?$expand=Contact,Address
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");
}
不幸的是,它一直生成以下内容:{?%3F%5C$expand%5C%3D=Contact,Address}
我尝试在uri字符串中添加反斜杠,但这并没有解决问题。