您好,我想检索属于登录用户的群组,我尝试使用以下代码,但它无法在服务器上运行。
using (System.Web.Hosting.HostingEnvironment.Impersonate())
{
string userName = HttpContext.Current.User.Identity.Name;
PrincipalContext domain = new PrincipalContext(ContextType.Domain);
UserPrincipal User = new UserPrincipal(domain);
User = UserPrincipal.FindByIdentity(domain, userName);
var strUnAuthorised = "";
if (User != null)
{
PrincipalSearchResult<Principal> gp = User.GetGroups();
foreach (Principal p in gp)
{
if (p.DisplayName == "xyz")
{
IsInGroup = true;
break;
}
}
}
}
在此之后,当我尝试从服务器读取一个xml文件时,我收到了未经授权的错误。请帮助我,我正在努力