Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling illegal query string parameter names in ASP.NET Web API

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!

like image 480
James Bender Avatar asked Sep 18 '25 02:09

James Bender


1 Answers

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();
    }
like image 187
John Avatar answered Sep 20 '25 18:09

John