我想将使用 ASP.NET MVC 应用程序的用户的 Windows 凭据传递给 WCF 服务。我只想通过配置来实现这一点,以便在代码中透明地发生。
(这个问题最初是以过于具体的方式提出的,正如在修订中可以看到的那样。我只是以更好的方式重新提出这个问题来回答我自己的问题,希望它可以帮助别人。事实证明这是一个非常简单的任务)。
最佳答案
在 web.config(客户端和服务器)中,<system.serviceModel>
添加/修改绑定(bind)部分,使其看起来像这样:
<basicHttpBinding>
<binding name="MyBasicBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
并且,将其添加到客户端 web.config <system.web>
部分:
<identity impersonate="true" />
<authentication mode="Windows" />
这两项更改将使最终用户成为 Web 请求的当前用户,然后该请求将在 WCF 消息中发送。
然后可以在服务器端检索用户,如下所示:
ServiceSecurityContext.Current.WindowsIdentity
关于asp.net - HowTo : Pass Windows user credentials of asp.net Intranet 用户到 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20094525/