c# - W3C (IIS) 日志记录不记录我的 WCF 服务的 ClaimsIdentity 用户名

标签 c# asp.net wcf iis

我的前端 Web 应用程序 (MVC) 使用不记名 key (SAML) 向 WCF 后端服务验证自身。身份验证工作正常并且 ClaimsIdentity 对象设置正确。但是,ClaimsIdentity 的用户名不会出现在 W3C IIS 日志记录中。在前端,用户名是 (IIS W3C) 日志记录的一部分,它不会出现在 WCF 服务上。

前端日志记录:

2016-02-02 16:10:24 xxx.xxx.xxx.xxx POST/mobile/Tasks/Tasks/443 Wit.329406069 xxx.xxx.xxx.xxx Mozilla/5.0+ (Windows+NT+6.1;+WOW64;+Trident/7.0;+BOIE9;NLNL;+rv:11.0)+like+Gecko 200 0 0 597 17504 937

后端日志记录:

2016-02-02 16:10:24 xxx.xxx.xxx.xxx POST/services/TaskService.svc - 443 - xxx.xxx.xxx.xxx - 200 0 0 1118 9239 765

后端日志记录中缺少用户名。

这是我使用的绑定(bind):

<ws2007FederationHttpBinding>
<binding>
  <security mode="TransportWithMessageCredential">
    <message issuedKeyType="BearerKey" establishSecurityContext="false">
      <tokenRequestParameters>
        <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
          <trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType>
          <trust:SecondaryParameters xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
            <trust:KeyType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer</trust:KeyType>
            <trust:CanonicalizationAlgorithm>http://www.w3.org/2001/10/xml-exc-c14n#</trust:CanonicalizationAlgorithm>
            <trust:EncryptionAlgorithm>http://www.w3.org/2001/04/xmlenc#aes256-cbc</trust:EncryptionAlgorithm>
          </trust:SecondaryParameters>
        </trust:SecondaryParameters>
      </tokenRequestParameters>
    </message>
  </security>
</binding>

最佳答案

IIS 只能在使用 Windows/基本(以及其他一些)身份验证方法时记录用户名。

在您的情况下,IIS 使用匿名身份验证,而您的应用程序处理真正的检查。因此,IIS 不记录任何内容,您必须使用自己的日志记录来跟踪用户。

关于c# - W3C (IIS) 日志记录不记录我的 WCF 服务的 ClaimsIdentity 用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35170821/

相关文章:

c# - 在 C# 中创建 session

c# - 将字符串的一部分放入数组

c# - 图像 TapGestureRecognizer 未在 Xamarin 中触发

c# - 如何从服务器端发布 HTML 表单?

java - Web 服务互操作性

wcf - 带有 RIA WCF 项目的 Silverlight 无法添加常规 WCF 服务引用

c# - WCF 添加命名空间属性

c# - AutoFixture 可以通过约定注册接口(interface)吗?

c# - 什么时候从继承类创建对象?

c# - 通过减少库存更新数据库 C# 和 mysql