c# - 如何列出请求用户在 WCF 服务中的角色?

标签 c# .net wcf security-roles

刚刚开始掌握 WCF 安全性。如何列出用户在服务中的角色?

例如

// Could use declarative security here, i.e. using PrincipalPermission attribute
public string MyService()
{
    // Would like some code that does something like:
    foreach( Role role in CurrentUser.Roles )
    {
    }
}

谢谢

最佳答案

处理 Windows 组时,您可以使用以下代码:

foreach (IdentityReference idRef in WindowsIdentity.GetCurrent().Groups)
{
    Console.WriteLine(idRef.Translate(typeof(NTAccount)).Value);
}

关于c# - 如何列出请求用户在 WCF 服务中的角色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/697065/

相关文章:

mysql - 首先在 WCF 服务中的何处为 EF6 代码设置 DbConfiguration?

c# - KitchenPC 和 Ironpython

.net - 如何获取 HttpWebRequest 连接到的服务器的 IP 地址?

wcf - WCF 流式处理问题

c# - 为什么.NET 框架不提供深度复制对象的方法?

c# - MVC2 C# TextAreaFor 包含 ', ,'

wcf - 使用 WCF WebApi 实现工作单元

c# - 如何创建一个将通用类作为其通用类型的通用类?

c# - 用于可选分配的可空类型(不是集合)的 Protobuf-net 模式

c# - 如何在C#中进行加减法运算?