我有一个 Silverlight 应用程序和一个使用 Windows 身份验证的 WCF 服务。 我的用户得到正确的身份验证。我可以在客户端访问他们的用户名和角色。 但是我如何在服务器端做同样的事情呢? 这个我试过了
ServiceSecurityContext.Current.WindowsIdentity
和
IIdentity caller = ServiceSecurityContext.Current.PrimaryIdentity;
这是我在 stackoverflow 上找到的类似问题的答案,但无法编译。 我收到“ServiceSecurityContext 不包含当前的定义”异常。
那么如何在服务器端获取用户呢?
最佳答案
public static string GetUserIdentity()
{
return OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
}
OperationContext 在 System.ServiceModel 命名空间中。
关于c# - 如何在 WCF 服务上使用 Windows 身份验证访问服务器端的用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8491296/