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:


The above property will return logged in user name with domain name. For example, it returns “DOMAIN\USER”.

1 comment:

  1. I have used the code as below:
    var user = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name

    but I am getting an error, 'Object reference not set'. I am using VS 2012.


DotNet Code Guru