سؤال

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!

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top