Kornél Regius
Kornél Regius

Reputation: 3049

ASP.NET Web Api custom parameter name

My API is expecting url parameters with a dot in their name. Examples:

my.param

my.otherparam

Because of the dot, I can't name the c# variables with the name of the parameters, because my.param is not a valid c# variable name.

Is there any way to give custom variable names?

What I want:

    //...?my.param=value1&my.otherparam=value2
    public string Get([Paramname="my.param"]string my_param,[Paramname="my.otherparam"]string my_otherparam)
    {...}

We are trying to work with a big company, therefore we must use their parameter naming.

Upvotes: 1

Views: 860

Answers (1)

Håkan Fahlstedt
Håkan Fahlstedt

Reputation: 2095

You can use Request-object in the call to get the content of the request:

public string Get()
{
  var query = HttpContext.Current.Request.QueryString;

   //Parse the parameter out of the query-variable

}

Upvotes: 1

Related Questions