Wednesday, April 7, 2010
Get Windows Username in WCF service method
For configuring windows authentication in WCF service, please refer my previous blog Windows Authentication in WCF
In some scenario, we need to find out the user name who calls WCF service method. You can find out current logged in user who called WCF service method using below code:
OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
The above property will return logged in user name with domain name. For example, it returns “DOMAIN\USER”.
Labels:
OperationContext,
Username,
WCF,
Windows Authentication,
WindowsIdentity
Subscribe to:
Post Comments (Atom)
I have used the code as below:
ReplyDeletevar user = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
but I am getting an error, 'Object reference not set'. I am using VS 2012.