Active Directory COM Exception - An operations error occurred (0x80072020)

前端 未结 8 906
灰色年华
灰色年华 2020-11-28 10:39

I am getting an intermittent COM Exception \"An operations error occurred (0x80072020)\" (shown below) when I try and query Active Directory using the metho

相关标签:
8条回答
  • 2020-11-28 11:16

    Granted this is 2 years later, I ran into this and found that the following solved my issue:

    using System.Web.Hosting;
    ...
    ...
    // Code here runs as the logged on user
    
    using (HostingEnvironment.Impersonate()) {
    // This code runs as the application pool user
         DirectorySearcher searcher ...
    }
    

    reference

    0 讨论(0)
  • 2020-11-28 11:20

    If you got a error code, "An operations error occurred (0x80072020)", it might mean "Access denied".

    • Check your Web server whether or not in AD Domain
      • If not you have to put authentication into PrincipalContext.
    Example (Something like this):
    public bool foo(String username, String password) {
        string ADIPaddress = "[ipaddress]";
        ContextOptions options = ContextOptions.Negotiate;
        PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, AD_IPaddress, null, options, username, password);
        bool isAuthenticated = principalContext.ValidateCredentials(username, password, options);
        return isAuthenticated;
    }
    
    Reference
    • C#網頁登入AD網域進行LDAP驗證
    0 讨论(0)
提交回复
热议问题