foreach (string key in HttpContext.Current.Request.Form.AllKeys)
{
string value = HttpContext.Current.Request.Form[key];
}
What is the .net core version of the above code? Seems like .net core took out AllKeys and replaced it with Keys instead. I tried to convert the above code to the .net core way, 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)
{
}
The HttpContext encapsulates all the HTTP-specific information about a single HTTP request. When an HTTP request arrives at the server, the server processes the request and builds an HttpContext object. This object represents the request which your application code can use to create the response.
Current. Item” data is live for single HTTP request/Response where HttpContext. Current. Session data is live throughout user's session.
HttpContext. Current. Application is simply a reference to the static global HttpApplicationState object in . NET for your Web Application, of which there should be one global instance per web application. By storing data there, you provide fast, thread-safe access to your global variables.
The Request property provides programmatic access to the properties and methods of the HttpRequest class. Because ASP.NET pages contain a default reference to the System. Web namespace (which contains the HttpContext class), you can reference the members of HttpRequest on an .
Your could use this:
var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());
In that case, you can iterate over your dictionary or you can access values directly:
dict["Hello"] = "World"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With