Ayman Idris
Ayman Idris

Reputation: 21

ServiceSecurityContext.Current.WindowsIdentity.Name is null

i'm using message security with a certificate authentication

        <basicHttpBinding>
            <binding name ="customBinding">
                <security mode="Message">
                    <message clientCredentialType="Certificate"/>
                </security>
            </binding>
        </basicHttpBinding>

i'm trying to log client user name, when i do this:

ServiceSecurityContext.Current.WindowsIdentity.Name

i get null. how can i retrieve the client's user name while using this security mode?

Upvotes: 2

Views: 3442

Answers (2)

gReX
gReX

Reputation: 1080

I have nothing to test, but may you can try mix transport-Window with message-Certificat. I'm really not sure, if this is possible.

<basicHttpBinding>
  <binding name ="customBinding">
     <security mode="Message">  
             <message clientCredentialType="Certificate" />  
             <transport clientCredentialType="Windows"/>
      </security>    
   </binding>
</basicHttpBinding>

and for your web.config:

<system.web><authentication mode="Windows"/></system.web>

For Reference: message-Windows https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/message-security-with-a-windows-client

message-Certificate https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/message-security-with-a-certificate-client

I got in my binding the username from the client with basicHttpBinding with Transport-Security (ssl):

<security mode="Transport">
     <transport clientCredentialType="Windows"/>
</security>

and without ssl:

<security mode="TransportCredentialOnly">
     <transport clientCredentialType="Windows"/>
</security> 

Be sure, IIS is configured with Authentication - WindowsAuthentication Enabled.

Hope this helps someone who is dealing with this.

Upvotes: 0

Raju S Nair
Raju S Nair

Reputation: 333

 <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>

ServiceSecurityContext Class uses windows authentication

Upvotes: 1

Related Questions