本文整理汇总了C#中DirectoryEntry.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry.Close方法的具体用法?C# DirectoryEntry.Close怎么用?C# DirectoryEntry.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DirectoryEntry
的用法示例。
在下文中一共展示了DirectoryEntry.Close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
string path= "LDAP://DC=[DOMAIN],DC=local";
string strAccountId = "[USERNAME]";
string strPassword = "[PASSWORD]";
bool bSucceeded;
string strError;
DirectoryEntry adsEntry = new DirectoryEntry(path, strAccountId, strPassword);
DirectorySearcher adsSearcher = new DirectorySearcher( adsEntry );
adsSearcher.Filter = "(sAMAccountName=" + strAccountId + ")";
try
{
SearchResult adsSearchResult = adsSearcher.FindOne();
bSucceeded = true;
strError = "User has been authenticated by Active Directory.";
adsEntry.Close();
}
catch ( Exception ex )
{
bSucceeded = false;
strError = ex.Message;
adsEntry.Close();
}
if (bSucceeded){
Console.WriteLine("Great Success");
}else {
Console.WriteLine("Great Fail");
}
}
示例2: Move
// Summary:
// Performs and LDAP move on this Principal
//
// Returns:
// Void
//
// Exceptions:
//
public void Move(string ldapPath, string newName)
{
/* This whole method is needed because AccountManagement does not provide a Principal.Move() method.
* So we have to peel back layers of the onion and do it ourselves.
*/
//For brevity, removed existence checks
var eLocation = new DirectoryEntry("LDAP://" + DistinguishedName);
var nLocation = new DirectoryEntry("LDAP://" + ldapPath);
if (string.IsNullOrEmpty(newName))
{
newName = eLocation.Name;
}
eLocation.MoveTo(nLocation, newName);
nLocation.Close();
eLocation.Close();
}
示例3: RemoveMember
// Summary:
// Removes the distinguished name of the supplied Principal object from the member attribute belonging to this GroupPrincipalFull
//
// Returns:
// void
//
// Exceptions:
//
public void RemoveMember(Principal principal)
{
var groupDe = new DirectoryEntry(string.Format("LDAP://{0}", DistinguishedName));
groupDe.Properties["member"].Remove(principal.DistinguishedName);
groupDe.CommitChanges();
groupDe.Close();
}
示例4: RemoveAllMembers
// Summary:
// Removes all members belonging to this GroupPrincipalFull
//
// Returns:
// void
//
// Exceptions:
//
public void RemoveAllMembers()
{
var groupDe = new DirectoryEntry(string.Format("LDAP://{0}", DistinguishedName));
groupDe.Properties["member"].Clear();
groupDe.CommitChanges();
groupDe.Close();
}
示例5: LookForUserInAllDomains
public static DataTable LookForUserInAllDomains(string sLastNameSearch, string sFirstNameSearch)
{
if (sUID == "") sUID = null;
if (sPwd == "") sPwd = null;
CreateNetworkUserTable();
objTable.Rows.Clear();
////Search in all the domains
//string ldapdomains = System.Configuration.ConfigurationManager.AppSettings["LDAPDomains"].ToString();
//string[] Domains = ldapdomains.Split(new char[] { ';' });
//for (int i = 0; i < Domains.Length; i++)
//{
// string domainName = Domains[i];
// objTable = LookForUserInDomain(domainName, sLastNameSearch, sFirstNameSearch);
//}
string sFilter = String.Format("(|(&(objectClass=User)(givenname={0})(sn={1})))", sFirstNameSearch, sLastNameSearch);
// collect inactive users in all the domains
string[] sDomains = sLDAPDomains.Split(new char[] { ';' });
for (int i = 0; i < sDomains.Length; i++ )
{
string sDomainName = sDomains[ i ];
string sServerName = System.Configuration.ConfigurationManager.AppSettings[sDomainName].ToString();
string sLDAPPath = "LDAP://" + sServerName + "/DC=" + sDomainName + ",DC=root01,DC=org";
DirectoryEntry objRootDE = new DirectoryEntry(sLDAPPath, sUID, sPwd, AuthenticationTypes.Secure);
DirectorySearcher objDS = new DirectorySearcher(objRootDE);
objDS.Filter = sFilter;
objDS.ReferralChasing = ReferralChasingOption.None;
objDS.PropertiesToLoad.Add("userAccountControl");
objDS.PropertiesToLoad.Add("SAMAccountName");
objDS.PropertiesToLoad.Add("givenName");
objDS.PropertiesToLoad.Add("sn");
objDS.PropertiesToLoad.Add("TelephoneNumber");
objDS.PropertiesToLoad.Add("mail");
SearchResultCollection objSRC = null;
try
{
objSRC = objDS.FindAll();
}
catch (Exception excpt)
{
if (excpt.Message.IndexOf("The server is not operational.") < 0)
throw;
}
if (objSRC == null)
continue;
foreach (SearchResult objSR in objSRC)
{
int iInactiveFlag = Convert.ToInt32(objSR.Properties["userAccountControl"][0]);
string sUserId = objSR.Properties["SAMAccountName"][0].ToString();
string sFirstName = objSR.Properties["givenName"][0].ToString();
string sLastName = objSR.Properties["sn"][0].ToString();
string sPhone = "";
string sEmail = "";
if (objSR.Properties["TelephoneNumber"].Count > 0)
sPhone = objSR.Properties["TelephoneNumber"][0].ToString();
if( objSR.Properties["mail"].Count > 0 )
sEmail = objSR.Properties["mail"][0].ToString();
iInactiveFlag = iInactiveFlag & 0x0002;
if (iInactiveFlag <= 0)
{
// add name, username, phone and email to the table, if active
DataRow objRow = objTable.NewRow();
objRow["LastName"] = sLastName;
objRow["FirstName"] = sFirstName;
objRow["Username"] = sUserId;
objRow["UserDomain"] = sDomainName;
objRow["Phone"] = sPhone;
objRow["Email"] = sEmail;
objTable.Rows.Add( objRow );
continue;
}
}
objSRC.Dispose();
objDS.Dispose();
objRootDE.Close();
objRootDE.Dispose();
}
return objTable;
}
示例6: RetrieveAllNetworkUsersFromLDAP
private static SearchResultCollection RetrieveAllNetworkUsersFromLDAP(string sDomainName)
{
string sServerName = System.Configuration.ConfigurationManager.AppSettings[sDomainName].ToString();
string sLDAPPath = "LDAP://" + sServerName + "/DC=" + sDomainName + ",DC=root01,DC=org";
DirectoryEntry objRootDE = new DirectoryEntry(sLDAPPath, sUID, sPwd, AuthenticationTypes.Secure);
DirectorySearcher objDS = new DirectorySearcher(objRootDE);
objDS.Filter = "(|(&(objectClass=User)(givenname=*)(sn=*)))";
objDS.ReferralChasing = ReferralChasingOption.None;
objDS.PropertiesToLoad.Add("userAccountControl");
objDS.PropertiesToLoad.Add("SAMAccountName");
SearchResultCollection objSRC = null;
try
{
objSRC = objDS.FindAll();
}
catch (Exception excpt)
{
if (excpt.Message.IndexOf("The server is not operational.") < 0)
throw;
}
objDS.Dispose();
objRootDE.Close();
objRootDE.Dispose();
return objSRC;
}