4

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!

1
  • what version of web api? Commented Aug 12, 2016 at 23:03

2 Answers 2

2

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();
    }
Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

This news will come as a huge shock to the odata folks
Agree... I was with a team that was part of defining OData some 10 years ago, and this was raised but didn't progress.

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.