HttpContext.Current.Request.Form.AllKeys in ASP.NET CORE version

foreach (string key in HttpContext.Current.Request.Form.AllKeys)
{
   string value = HttpContext.Current.Request.Form[key];
}

      

What is the .net core version for the above code? It looks like the .net kernel has extracted AllKeys and replaced it with Keys instead . I tried converting the above code to the main .net path, but it throws an invalid operation exception.

HttpContext.Request.Form = 'HttpContext.Request.Form' threw an exception of type 'System.InvalidOperationException'

Converted code:

foreach (string key in HttpContext.Request.Form.Keys)
{      
}

      

+3


source to share


1 answer


You could use this:

var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());

      



In this case, you can iterate over your dictionary, or you can access the values ​​directly:

dict["Hello"] = "World"

      

+5


source







All Articles