I'm looking for the simplest way of converting a query string from an HTTP GET request into a Dictionary, and back again.

I figure it's easier to carry out various manipulations on the query once it is in dictionary form, but I seem to have a lot of code just to do the conversion. Any recommended ways?

AspNet Core now automatically includes <code>HttpRequest.Query</code> which can be used similar to a dictionary with key accessors.

However if you needed to cast it for logging or other purposes, you can pull out that logic into an extension method like this:

public static class HttpRequestExtensions
{
  public static Dictionary<string, string> ToDictionary(this IQueryCollection query)
  {
    return query.Keys.ToDictionary(k => k, v => (string)query[v]);
  }
}

Then, you can consume it on your httpRequest like this:

var params = httpRequest.Query.ToDictionary()

Further Reading