2012-01-03 22 views
7

Dürüst olmak gerekirse, nasıl sorulacağından emin değilim. Aslında, çalıştırdığımda yerel makinemde fevkalade çalışan bir kodum var. Geliştirme web sunucumuza yayınladığımda başarısız olur. Bir IIS kurulum sorunu, web.config sorunu veya kodlama sorunu olup olmadığından emin değilim.C# Active Directory PrincipalContext/UserPrincipal.IsMemberOf hatası

Burada bir kullanıcı adı ve bir grup geçmesi kod

bool isMember = false; 

    PrincipalContext ADDomain = new PrincipalContext(ContextType.Domain); 
    UserPrincipal user = UserPrincipal.FindByIdentity(ADDomain, userID); 

    if (user.IsMemberOf(ADDomain, IdentityType.Name, groupName.Trim())) 
    { 
     isMember = true; 
    } 

    return isMember; 

snippet'i ve bu kullanıcı bu gruptaki bir üyesi eğer söylüyor. Sorun değil. Makinemde harika çalışıyor. Ben web sunucusu bu kodu yayımlamak gitti ve çizgi bu hatayı atar

UserPrincipal user = UserPrincipal.FindByIdentity(ADDomain, userID); 

çarptığında başarısız:

[DirectoryServicesCOMException (0x80072020): An operations error occurred.]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +788
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_AdsObject() +42
System.DirectoryServices.PropertyValueCollection.PopulateList() +29
System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +63
System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +163 System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() +521217
System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() +51
System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +141
System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +42
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) +29
System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, String identityValue) +95
Cosmic.Web.Login.btnSubmit_Click(Object sender, EventArgs e) in C:\cosmic\Cosmic.Web\Login.aspx.cs:79
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691

Herhangi bir fikir bu başarısız olabilir?

cevap

17

İlk tahminim şöyle olurdu: Bu kodu altında çalıştırdığınız kullanıcı hesabı, Active Directory'yi sorgulamak için gerekli izinlere sahip değil.

PrincipalContext ADDomain = new PrincipalContext(ContextType.Domain); 

(bu kod altında çalıştığı akım, varsayılan kimlik bilgileriyle AD bağlantı kurar):

temelde bu sizin yapıcı değiştirmeniz gerekir Bunu düzeltmek için Bu, yeterli ayrıcalıklara sahip olduğunu bildiğiniz bir kullanıcı hesabı için bir kullanıcı adı ve parola sağlayın ve kullanıcı adı ve parola sağlayın. o Active Directory'yi sorgula.

+1

Bunun ne olduğunu biliyorsunuz. Web sunucusu, Active Directory'ye basmak için doğru kimlik bilgilerine sahip değil. Orada bazı kimlik bilgileri koyun ve biraz daha iyi çalışır. Teşekkürler! – Seril