当他使用 WCF 服务时,我可以获得请求者 windows IPrincipal 吗?
1591 次
1 回答
5
使用此代码,您可以检查 WCF 服务中的当前安全上下文。
如果用户已通过身份验证,并且 WindowsPrincipal 不为空,那么您使用的是 Windows 安全模型 - 您可以访问所有相关信息:
ServiceSecurityContext current = ServiceSecurityContext.Current;
if (!current.IsAnonymous && current.WindowsIdentity != null)
{
string userName = current.WindowsIdentity.Name;
}
于 2009-06-14T15:42:14.663 回答