开发者

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

开发者 https://www.devze.com 2023-04-05 07:54 出处:网络
Hi I want to retrieve the groups belonging to logged in user I tried following code but it is not working 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

精彩评论

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