2009-06-14 93 views
4

当他使用WCF服务时,我可以得到请求者的Windows IPrincipal吗?来自WCF请求的IPrincipal

+0

也许。真的需要更多的信息来了解你如何访问服务。 – 2009-06-14 15:18:34

+0

那么,我使用WCF使用Windows身份验证,我配置特定用户到应用程序池,因此它将具有数据库凭据。哪些更多细节必需品? thanx – Tamir 2009-06-14 15:27:09

回答

5

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

如果用户进行身份验证,而WindowsPrincipal不为空,那么你使用的是Windows安全模式 - 你可以访问所有相关的信息:

ServiceSecurityContext current = ServiceSecurityContext.Current; 

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