Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

554
Views
Can't get query parameter from HttpRequestData

I'm upgrading my code from .NET 3.0 to .NET 5.0, this changes the sintaxis quite a bit. In my previous code, which is a http request build in AZURE FUNCTIONS .NET 5.0 isolate, builds an GET api that takes parameters.

This is my previous code from .NET 3.0

using Microsoft.Azure.WebJobs; 
using Microsoft.Azure.WebJobs.Extensions.Http;


public static async Task<IActionResult> Run(
  [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
  ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");
    byte[] RSA_Key_to_Correct = new byte[0x80];
    string array_var = req.Query["array_var"];
    string i = req.Query["i"];
    string incrementing_value = req.Query["incrementing_value"];
}

I just cant find a way to use req to grab a parameter from the api call like it was done on .NET 3.0 string i = req.Query["i"];

In .NET 5.0 im using

using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;

Any hint?

over 4 years ago · Santiago Trujillo
5 answers
Answer question

0

In Azure function .NET 5.0, we use the HttpRequestData in Http Trigger. The class does not contain Query parameter. For more details, please refer to here enter image description here

So if you want to get query string, you can use the package Microsoft.AspNetCore.WebUtilities.QueryHelpers to implement it as @user1672994 said.

For example

var queryDictionary = 
    Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(req.Url.Query);
var result = queryDictionary["<key name>"];
over 4 years ago · Santiago Trujillo Report

0

You can just add the the query parameter name to the function parameter list as follows and access the value:

public static async Task<IActionResult> Run(
      [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, 
      ILogger log, string parameter1)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
        log.LogInformation($"Parameter Value: {parameter1}");

    }
over 4 years ago · Santiago Trujillo Report

0

There is a system package that gives the same result. That is probably why it was removed. Just use:

var query = System.Web.HttpUtility.ParseQueryString(req.Url.Query);
var from = query["key"]

This gives the same result as req.Query["array_var"];

Enjoy 😉

over 4 years ago · Santiago Trujillo Report

0

If you are using Azure Functions (isolated) with .NET 5.0 - you can get it out of FunctionContext.BindingContext.BindingData like this:

functionContext.BindingContext
               .BindingData["weatherForecastId"]
               .ToString();
[Function("WeatherForecastGet")]
public async Task<HttpResponseData> Get([HttpTrigger(AuthorizationLevel.Function, "get", Route = "weather/{weatherForecastId:required}")] HttpRequestData req,
                                        FunctionContext executionContext)
{
    string weatherForecastId = executionContext.BindingContext
                                               .BindingData["weatherForecastId"]
                                               .ToString();

    var result = this.doSomething(weatherForecastId);
    
    var response = req.CreateResponse(HttpStatusCode.OK);
    await response.WriteAsJsonAsync(result);

    return response;
}

As the question asked about the HttpRequestData. The FunctionContext is also available in it. So you can achieve the same results (with more steps) like this:

httpRequestData.FunctionContext
               .BindingContext
               .BindingData["weatherForecastId"]
               .ToString();
[Function("WeatherForecastGet")]
public async Task<HttpResponseData> Get([HttpTrigger(AuthorizationLevel.Function, "get", Route = "weather/{weatherForecastId:required}")] HttpRequestData req,
                                        FunctionContext executionContext)
{
    string weatherForecastId = req.FunctionContext
                                  .BindingContext
                                  .BindingData["weatherForecastId"]
                                  .ToString();

    // some logic
}

This also works with the parameter in both query and path. As you can see both parameters in the API path below is in the BindingData

/api/weather/12?range=today

Debugger

over 4 years ago · Santiago Trujillo Report

0

This works for me. Nice and simple. There is a method to get the query params into a dictionary.

var qp = req.GetQueryParameterDictionary();

var foobar = req["foobar"]; 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!