asp.net - HowTo : Pass Windows user credentials of asp.net Intranet 用户到 WCF 服务

标签 asp.net wcf authentication intranet

我想将使用 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/

相关文章:

json - 使用 Rails 3 应用程序的 ios json 身份验证

javascript - Phonegap + Sencha + Android : ajax request with a basic access authentication failled

ASP.NET应用程序池回收问题

c# - 在 WCF 中将 ContractNamespace 用于命名空间枚举

c# - 从 CRM 沙盒插件调用 WCF(使用生成的客户端)抛出 System.Security.SecurityException

c# - 从远程计算机调用 Windows 服务

node.js - 使用node.js和passport进行身份验证后重定向到上一页

asp.net - 为什么 < 在运行时被转换为 <

c# - 锁定静态方法

c# - ShowHeaderWhenEmpty、EmptyDataText 和 EmptyDataTemplate 在 gridview 中不起作用