3

I have a client that is sending me a query string where several of the parameters begin with a dollar ($) sign. I can't start my parameters' names in C# with $, which means that the values are not mapping when my action is being called.

Before anyone asks, no I cannot have the client change the name of the query string.

I have a feeling I'm going to have to write some sort of custom action filter to find these parameters, rename them and then pass them on to the correct action. But, before I did all that, I wanted to post the question here to see if there's a solution I'm missing.

Thanks!

Luiso
  • 4,173
  • 2
  • 37
  • 60
James Bender
  • 1,175
  • 1
  • 11
  • 22

2 Answers2

1

Unfortunately, $ should not be used as part of the parameter names, as it is reserved in the URI definition

What does dollar sign $ do in url?

So the query string you are receiving is formally incorrect, and the best solution would be to change it, as future Http implementations or even some firewalls may break your solution.

A work around would be to override the query string parser, and access the URI directly, using HttpRequest properties Url (maybe the query method) or RawUrl:

https://msdn.microsoft.com/en-us/library/system.web.httprequest.url(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/system.web.httprequest.rawurl(v=vs.110).aspx

Community
  • 1
  • 1
Bruno Guardia
  • 453
  • 4
  • 14
1

This is how I handled the issue:

    [HttpGet, Route("myResource")]
    public virtual IHttpActionResult GetThings()
    {
        var query = HttpUtility.ParseQueryString(Request.RequestUri.Query);
        var queryParam = query["$myParam"];

        return Ok();
    }
John
  • 17,163
  • 16
  • 65
  • 83