I am working on writing a web api for my application that is currently written using ASP.NET Web Forms. I have a module that acquires some data at the beginning of the request and stores it in HttpContext.Current.Items so that it is available to all code later during the page processing.
I am trying to write my web api and it needs to do the same thing. What is the correct way to store "per request" global data to be used during processing for a web api controller (I suspect it would be the same for a regular controller as well).
Also, if there is a way to do so, is there a way to set this data in an IHttpModule that runs prior to the controller being instantiated.
Any help is appreciated!
The HttpConfiguration is the main class which includes following properties using which you can override the default behaviour of Web API. Property. Description. DependencyResolver. Gets or sets the dependency resolver for dependency injection.
7+ Million HTTP requests per second from a single server.
You can use the HttpRequestMessage.Properties
dictionary as per this StackOverflow question.
There are other options like HttpContext or Session, but they can't be used in a self-hosting setup, only in WebHosting mode.
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