【发布时间】:2014-03-09 00:42:59
【问题描述】:
我正在为 WPF 应用程序开发业务逻辑。在应用程序启动之前,我必须证明 CurrentUser 是否在一个特殊域的 ActiveDirectory 中,如果他在那里,我必须找出当前用户的角色。当前用户和他在 AD 中的存在工作正常,但我很难找出角色。
我试过了:
using System.Web.Security;
Roles.GetRolesForUser(currentuser);
但问题是,我必须启用角色管理,所以我在代码上方写了:
Roles.Enabled = true;
但是还是有问题 --> System.InvalidOperationException;
这是整个代码(测试版):
string currentuser = Environment.UserName;
string currentmachine = Environment.MachineName;
if (DirectoryEntry.Exists(string.Format("WinNT://{0}/{1}", currentmachine, currentuser)))
{
Console.WriteLine("it's working\n");
Roles.Enabled = true;
Console.WriteLine(Roles.GetRolesForUser(currentuser));
}
else
{
Console.WriteLine("it's not working");
}
是 using 指令的问题吗?或者是否有其他可能性来检查用户的角色?
非常感谢。
【问题讨论】:
标签: c# wpf active-directory roles