This is the URL that comes to my server:
https://example.com/path?key-one=value&key-two=value2
And I want to convert it to this URL, but I don't want to redirect the user. So I need to rewrite:
https://example.com/path?keyOne=value&keyTwo=value2
In other words, I want to change the kebab-cased query keys into camelCased keys.
How can I do that?
This is what I have tried:
app.Use(async (context, next) =>
{
var collection = context.Request.Query;
var oldQueryString = context.Request.QueryString;
var newQueryString = new List<QueryString>();
foreach (var item in collection)
{
var camelizedKey = item.Key.Underscore().Camelize();
// what should I do here? How do I set the new query, how do I rewrite?
}
await next.Invoke();
});
Request.QueryString is readonly, but you can replace it with a new instance.
You can change the querystring of the current request with the following line:
Example: