How to store global request data in a .NET Web API project

I am working on writing a web api for my application, which is currently written using ASP.NET web forms. I have a module that receives 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 page processing.

I am trying to write my web api and it should do the same. What is the correct way to store global “on request” data that will be used during processing for the api web controller (I suspect this will be the same for a regular controller).

Also, if there is a way to do this, is there a way to set this data in the IHttpModule module, which runs before the controller is instantiated.

Any help is appreciated!

+6
source share
1 answer

You can use the HttpRequestMessage.Properties dictionary according to fooobar.com/questions/953452 / ....

There are other parameters, such as HttpContext or Session, but they cannot be used in setting up self-hosting only in WebHosting mode.

+4
source

Source: https://habr.com/ru/post/953450/


All Articles