tags:

views:

133

answers:

2

I use this code to authenticate to my WCF Service:

proxy.ClientCredentials.UserName.UserName = "test";
proxy.ClientCredentials.UserName.Password = "pass";

Is there any way to access this information from within a method of my WCF Service code? (I'm not interested in the password used, more the username for audit purposes.)

I'm trying to determine the identity of the user calling the method without changing the method signiture to include another parameter.

+2  A: 

Have you tried looking into the ServiceSecurityContext?

tomasr
That would be it
Abhijeet Patel
+3  A: 

You can retrieve the user name of the caller like this:

ServiceSecurityContext ssc = ServiceSecurityContext.Current;

if (!ssc.IsAnonymous && ssc.PrimaryIdentity != null)
{
    string userName = ServiceSecurityContext.Current.PrimaryIdentity.Name;
}

The PrimaryIdentity will contain a "normal" IIdentity and has all the fields (like IsAuthenticated etc.) that the identity object class carries.

Marc

marc_s