简体   繁体   English

查找WCF服务调用方的Active Directory域用户名

[英]Find a WCF service caller's Active Directory domain username

Consider a WCF service using WsHttpBinding for which only the domain users are allowed to call this service. 考虑使用WsHttpBinding的WCF服务,只允许域用户调用此服务。

How can you find the Active Directory username of the caller? 如何找到呼叫者的Active Directory用户名?

Get the value of System.ServiceModel.ServiceSecurityContext.Current.WindowsIdentity.Name property. 获取System.ServiceModel.ServiceSecurityContext.Current.WindowsIdentity.Name属性的值。

It does not matter which binding you use as long as the security mode is different from None for the binding. 只要安全模式与绑定的None不同,使用哪种绑定无关紧要。

If the security mode is None then System.ServiceModel.ServiceSecurityContext.Current will be null . 如果安全模式为NoneSystem.ServiceModel.ServiceSecurityContext.Current将为null

You can get identity of the user by calling: 您可以通过以下方式获取用户的身份:

ServiceSecurityContext.Current.WindowsIdentity.Name

or 要么

OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name

You will have to add some sort of User information to the message structure you are using to contact the service. 您必须将某种用户信息添加到用于联系服务的消息结构中。

eg 例如

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; }
}

This way you can query active directory at your client side, populate the UserInformation object and send over the user details as part of the message structure. 这样,您可以在客户端查询活动目录,填充UserInformation对象并作为消息结构的一部分发送用户详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM