سؤال

I would like to pass the Windows credentials of the user using my ASP.NET MVC application to a WCF service. I want to achieve this via configuration only so that this happens transparently in code.


(This question was originally asked in a too specific manner, as can be seen in the revisions. I only re-asked this in a better way to answer my own in hopes it might help someone. It turned out to be a pretty simple task).

هل كانت مفيدة؟

المحلول

In the web.config (client and server), in the <system.serviceModel> section add/modify a binding to look something like this:

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

And, add this to client side web.config <system.web> section:

<identity impersonate="true" />
<authentication mode="Windows" />

The two changes will make the end-user the current user of the web request which will then be sent in the WCF message.

The user can then be retrieved on the server side like this:

ServiceSecurityContext.Current.WindowsIdentity
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top