【问题标题】:IPrincipal from WCF request来自 WCF 请求的 IPrincipal
【发布时间】:2010-11-02 20:11:33
【问题描述】:

当请求者使用 WCF 服务时,我可以获取请求者 windows IPrincipal 吗?

【问题讨论】:

  • 也许吧。确实需要更多关于您如何访问服务的信息。
  • 好吧,我正在使用 WCF 使用 Windows 身份验证,我将特定用户配置到应用程序池,因此它将具有数据库凭据。需要哪些更多细节?谢谢
  • 您使用什么绑定/协议?客户端和服务器是否在同一个网段/Active Directory域?

标签: c# .net wcf security wcf-security


【解决方案1】:

使用此代码,您可以检查 WCF 服务中的当前安全上下文。

如果用户已通过身份验证,并且 WindowsPrincipal 不为空,那么您使用的是 Windows 安全模型 - 您可以访问所有相关信息:

ServiceSecurityContext current = ServiceSecurityContext.Current;

if (!current.IsAnonymous && current.WindowsIdentity != null)
{
    string userName = current.WindowsIdentity.Name;
}

【讨论】:

  • 非常感谢!我无法以某种方式将此标记为答案。不管怎样,谢谢你。塔米尔
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-03
  • 1970-01-01
  • 2011-04-06
  • 1970-01-01
  • 1970-01-01
  • 2015-04-03
  • 2016-08-13
相关资源
最近更新 更多