Find a WCF service caller's Active Directory domain username

Arian picture Arian · Feb 1, 2011 · Viewed 7.5k times · Source

Consider a WCF service using WsHttpBinding for which only the domain users are allowed to call this service.

How can you find the Active Directory username of the caller?

Answer

Rest Wing picture Rest Wing · Feb 1, 2011

Get the value of System.ServiceModel.ServiceSecurityContext.Current.WindowsIdentity.Name property.

It does not matter which binding you use as long as the security mode is different from None for the binding.

If the security mode is None then System.ServiceModel.ServiceSecurityContext.Current will be null.