Note that there are some explanatory texts on larger screens.

plurals
  1. POServiceSecurityContext.Current is null in WCF
    text
    copied!<p>I'm trying to retrieve the logged in windows user in a WCF service. I've tried using ServiceSecurityContext but Current is always null.</p> <pre><code>ServiceSecurityContext.Current.WindowsIdentity.Name </code></pre> <p>I've also tried using OperationContext. In this case ServiceSecurityContext returns as null.</p> <pre><code>OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name </code></pre> <p>Here's my web.config:</p> <pre><code> &lt;bindings&gt; &lt;basicHttpBinding&gt; &lt;binding name="HttpWindowsBinding"&gt; &lt;security mode="TransportCredentialOnly"&gt; &lt;transport clientCredentialType="Windows" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/basicHttpBinding&gt; &lt;/bindings&gt; </code></pre> <p>also</p> <pre><code>&lt;authentication mode="Windows"/&gt; </code></pre> <p>Can anyone see what I'm doing wrong?</p> <p>UPDATE: I abandoned trying to get ServiceSecurityContext to work. In the end, I found a solution by setting aspNetCompatibilityEnabled="true".</p> <pre><code>&lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /&gt; </code></pre> <p>I also added the following attribute to my service class:</p> <pre><code>[System.ServiceModel.Activation.AspNetCompatibilityRequirements(RequirementsMode = System.ServiceModel.Activation.AspNetCompatibilityRequirementsMode.Required)] </code></pre> <p>This allowed me to retrieve the windows user with:</p> <pre><code>HttpContext.Current.User.Identity.Name </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload