【发布时间】:2011-06-19 04:33:57
【问题描述】:
考虑使用WsHttpBinding 的 WCF 服务,仅允许域用户调用该服务。
如何找到调用者的 Active Directory 用户名?
【问题讨论】:
标签: c# wcf wcf-security
考虑使用WsHttpBinding 的 WCF 服务,仅允许域用户调用该服务。
如何找到调用者的 Active Directory 用户名?
【问题讨论】:
标签: c# wcf wcf-security
获取System.ServiceModel.ServiceSecurityContext.Current.WindowsIdentity.Name 属性的值。
只要安全模式与绑定的None 不同,您使用哪种绑定都没有关系。
如果安全模式是None,那么System.ServiceModel.ServiceSecurityContext.Current 将是null。
【讨论】:
Name 属性仅填充了Windows 身份验证模式。
您可以通过调用获取用户的身份:
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 对象并将用户详细信息作为消息结构的一部分发送。
【讨论】: