Thread.CurrentThread store custom data such as userid

In .net 4, Is it possible to store custom value such as userid in Thread.CurrentThread object?

I am trying to store userid for wcf client on the client side of MessageInspector in AfterReceiveRequest method as follows:

request.Headers.Add(MessageHeader.CreateHeader("userid", string.Empty, userid));

On the server side I would like to retrieve it in a Thread.CurrentThread in the method AfterReceiveRequest.

Is this possible?


ThreadStatic is not recommended because WCF will randomly use threads from the thread pool and ThreadStatic variables will not be reinitialized when the threads are recycled. Also if you have a session with multiple WCF calls, the same service instance is likely to switch threads from call to call.

You should create an OperationContext extension.

See Where to store data for current WCF call? Is ThreadStatic safe?

Need Your Help

Python 2.7 PANDAS grouping data by value ranges

python-2.7 pandas

I have a csv file that shows parts on order. The columns include days late, qty and commodity.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.