I am using a WCF Service and I have implemented IErrorHandler. In the HandleError method, I want to retrieve the caller's username in order to set a ThreadContext property for Log4Net (to save the username along with the exception details in SQL Server)
My code is working well if I avoid trying to retrieve the caller's username.
This is the line of code inside the HandleError method which is returning a NullReferenceException:
string username = ServiceSecurityContext.Current.WindowsIdentity.Name;
It seems that at the point the HandleError method of IErrorHandler kicks in, the original caller information has been disposed.
Does anyone have any idea how I can retrieve the caller's username inside the HandlerError method of IErrorHandler?
Thanks for your help!