0

I am moving some functions to .net 5 isolated process but I am not sure about how to extract data using the new HttpRequestData in .net core I could do req.Query["blah"]

How do you do it in .net 5 with HttpRequestData?

.net 3.1

public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
        string fieldA = req.Query["fieldA"];
        string fieldB = req.Query["fieldB"];

        //etc...        
}

.net 5

 public  async Task<IActionResult>  Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, FunctionContext executionContext)
 {
        
        string fieldA = //????  req.Query["fieldA"];
        string fieldB = //???req.Query["fieldB"];

            //etc..             
 }

1 Answer 1

1

HttpRequestData.Url Property has Uri.Query Property.

You can use

var queryDictionary = 
    Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(
       HttpRequestData.Url.Query);

As suggested in Parse and modify a query string in .NET Core

Sign up to request clarification or add additional context in comments.

2 Comments

Hi thanks for your reply, it seems a bit of a step back, surely there must be a better way to do this.
@developer9969, I don’t understand what is the step back? I’ve updated the answer to make it a bit clear. Have you found a better way since then?

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.