I am trying to pass user information from controller to service layer.
IClientMessageInspectors
and IDispatchMessageInspectors
seem to be the most likely solution.
After going through Building an HTTP User Agent Message Inspector and Writing a WCF Message Inspector I have got a fair idea how to add information to the message header and how to read it.
What I cant figure out is this:
How do I get User information in the
IClientMessageInspector
?Inside the controller I used to sue
User.Identity.Name
. But the User object is not available in the message inspector. One way to have this information in the message inspector would be to pass it in the constructor, but I never explicitly create the MessageInspector object so how can I pass the user information in its constructor.Edit: I found the answer to my first question. The user information can be fetched by System.Threading.Thread.CurrentPrincipal.Identity.Name. Still stuck with the second part.
How to have the user information available inside a service method?
I can go through the headers and fetch the user information from the message header in the DispatchMessageInspector, but how can I have this information available in one of my operation contract?