How to store data per request with WebAPI

This is going to be a short one.

If you need to store some data and make it available to methods the most logical place to me is HttpContext. More precisely HttpContext.Current.Items collection which should always be available during a request processing.

So basically, in order to add the item you’ll need later during the request processing, you can do this

And for retrieving it in another place, this

Hope this helps

Happy coding, have fun.

One thought on “How to store data per request with WebAPI

Leave a Reply

Your email address will not be published. Required fields are marked *