c# - 如何在 WCF 服务上使用 Windows 身份验证访问服务器端的用户名?

标签 c# wcf silverlight wcf-ria-services windows-authentication

我有一个 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/

相关文章:

c# - 如何检查两个不同的 URL 是否指向同一个资源?

silverlight - 带有 WCF 的 Silverlight 中的跨域策略错误

windows - Kindle for Windows Phone 7 中使用的控件是什么

c# - 如何设置具有多个值以及单个 w/custom 属性的 ExportMetaData?

c# - 哪个版本的 sdk 和 .NET 与 visual studio express c# 2008 一起出现?

c# - 只有一个元素的数组到达 Controller

silverlight - Windows Phone 7 应用程序中较小的 PanoramaItems

c# - 网络作业 : Library not found

wcf - WCF 环境中的 F# 类型实例标识错误?

silverlight - 是否可以在Silverlight 5中显示隔离存储路径