[英]Find a WCF service caller's Active Directory domain username
考虑使用WsHttpBinding
的WCF服务,只允许域用户调用此服务。
如何找到呼叫者的Active Directory用户名?
获取System.ServiceModel.ServiceSecurityContext.Current.WindowsIdentity.Name
属性的值。
只要安全模式与绑定的None
不同,使用哪种绑定无关紧要。
如果安全模式为None
则System.ServiceModel.ServiceSecurityContext.Current
将为null
。
您可以通过以下方式获取用户的身份:
ServiceSecurityContext.Current.WindowsIdentity.Name
要么
OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
您必须将某种用户信息添加到用于联系服务的消息结构中。
例如
public class UserInformation
{
public string User { get; set; }
public string Password { get; set; }
}
[DataContract]
public class Request
{
[DataMember]
public UserInformation User { get; set; }
[DataMember]
public MyRequest RequestBody { get; set; }
}
这样,您可以在客户端查询活动目录,填充UserInformation对象并作为消息结构的一部分发送用户详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.