【问题标题】:Sharepoint 2010 not binding to Active DirectorySharepoint 2010 未绑定到 Active Directory
【发布时间】:2013-03-25 14:45:14
【问题描述】:

我正在尝试从活动目录中获取用户的管理员名称,我创建了一个控制台程序来测试它并且一切正常,当我在我的 Sharepoint 2010 程序中尝试代码时,它只是给了我异常“发生操作错误”。

在进一步调试后,我发现我的 principalcontext 出现错误,引发异常“为了执行此操作,必须在连接上完成成功的绑定。”代码如下(注意:try catch 中的代码与我在控制台应用程序中的代码完全相同。):

   public override void ItemAdding(SPItemEventProperties properties)
   {
       base.ItemAdding(properties);

       try 
       {
               // set up domain context
               PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

               // find a user
               UserPrincipal user = UserPrincipal.FindByIdentity(ctx, Environment.UserName);
               string samAccountName = "";


               if (user != null)
               {
                   // do something here....     
                   samAccountName = user.SamAccountName;
               }


               //Get the manager name from the active directory
               var domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;

               using (DirectoryEntry dir = new DirectoryEntry("LDAP://" + domain))
               {
                   using (DirectorySearcher ds = new DirectorySearcher(dir, "samAccountName=" + samAccountName))
                   {

                       SearchResult result = ds.FindOne();

                       string managerName = result.Properties["manager"][0].ToString();
                   }
               }



       }
       catch(Exception ex)
       {
           var message = ex.Message;

       }
   }

【问题讨论】:

  • ApplicationPoolIdentity 是否作为 NetworkService 运行?

标签: c# .net binding sharepoint-2010 active-directory


【解决方案1】:

尝试改变:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAINNAME");

【讨论】:

    猜你喜欢
    • 2016-05-05
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    相关资源
    最近更新 更多