开发者

Hosting environment.impersonate is not woking with System.DirectoryServices.AccountManagement on the server

Hi I want to retrieve the groups belonging to logged in user I tried following code but it is not working on the server.

   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 strUnA开发者_Go百科uthorised = "";
    if (User != null)
    {
        PrincipalSearchResult<Principal> gp = User.GetGroups();
        foreach (Principal p in gp)
        {
            if (p.DisplayName == "xyz")
            {
                IsInGroup = true;
                break;
            }
        }
    }
}

after this when I am trying to read one xml file from the server I am getting not authorised error. please help me I am struggling alot

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜