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. If you are suffering from a sport lesion you may a need a orthopedic surgeon.

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.

Leave a Reply

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