本文整理汇总了C#中DirectoryEntry.Bind方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry.Bind方法的具体用法?C# DirectoryEntry.Bind怎么用?C# DirectoryEntry.Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DirectoryEntry
的用法示例。
在下文中一共展示了DirectoryEntry.Bind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActiveDirectorySchemaClass
public ActiveDirectorySchemaClass(DirectoryContext context, string ldapDisplayName)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if ((context.Name == null) && (!context.isRootDomain()))
{
throw new ArgumentException(Res.GetString(Res.ContextNotAssociatedWithDomain), "context");
}
if (context.Name != null)
{
// the target should be a valid forest name or a server
if (!((context.isRootDomain()) || (context.isADAMConfigSet()) || (context.isServer())))
{
throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context");
}
}
if (ldapDisplayName == null)
{
throw new ArgumentNullException("ldapDisplayName");
}
if (ldapDisplayName.Length == 0)
{
throw new ArgumentException(Res.GetString(Res.EmptyStringParameter), "ldapDisplayName");
}
_context = new DirectoryContext(context);
// validate the context
_schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.SchemaNamingContext);
_schemaEntry.Bind(true);
_ldapDisplayName = ldapDisplayName;
// the common name will default to the ldap display name
_commonName = ldapDisplayName;
// set the bind flag
this.isBound = false;
}
示例2: IsContextValid
//.........这里部分代码省略.........
// we can get this error if the target it server:port (not a valid forest)
contextIsValid = false;
}
else if (errorCode != 0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
}
else
{
Debug.Assert(domainControllerInfo != null);
Debug.Assert(domainControllerInfo.DnsForestName != null);
context.serverName = domainControllerInfo.DnsForestName;
contextIsValid = true;
}
}
else if (contextType == DirectoryContextType.ApplicationPartition)
{
Debug.Assert(context.Name != null);
// check for application partition
int errorCode = 0;
DomainControllerInfo domainControllerInfo;
errorCode = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)PrivateLocatorFlags.OnlyLDAPNeeded, out domainControllerInfo);
if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
{
// try with force rediscovery
errorCode = Locator.DsGetDcNameWrapper(null, context.Name, null, (long)PrivateLocatorFlags.OnlyLDAPNeeded | (long)LocatorOptions.ForceRediscovery, out domainControllerInfo);
if (errorCode == NativeMethods.ERROR_NO_SUCH_DOMAIN)
{
contextIsValid = false;
}
else if (errorCode != 0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
}
else
{
contextIsValid = true;
}
}
else if (errorCode == NativeMethods.ERROR_INVALID_DOMAIN_NAME_FORMAT)
{
// we can get this error if the target it server:port (not a valid application partition)
contextIsValid = false;
}
else if (errorCode != 0)
{
throw ExceptionHelper.GetExceptionFromErrorCode(errorCode);
}
else
{
contextIsValid = true;
}
}
else if (contextType == DirectoryContextType.DirectoryServer)
{
//
// if the servername contains a port number, then remove that
//
string tempServerName = null;
string portNumber;
tempServerName = Utils.SplitServerNameAndPortNumber(context.Name, out portNumber);
//
// this will validate that the name specified in the context is truely the name of a machine (and not of a domain)
//
DirectoryEntry de = new DirectoryEntry("WinNT://" + tempServerName + ",computer", context.UserName, context.Password, Utils.DefaultAuthType);
try
{
de.Bind(true);
contextIsValid = true;
}
catch (COMException e)
{
if ((e.ErrorCode == unchecked((int)0x80070035)) || (e.ErrorCode == unchecked((int)0x80070033)) || (e.ErrorCode == unchecked((int)0x80005000)))
{
// if this returns bad network path
contextIsValid = false;
}
else
{
throw ExceptionHelper.GetExceptionFromCOMException(context, e);
}
}
finally
{
de.Dispose();
}
}
else
{
// no special validation for ConfigurationSet
contextIsValid = true;
}
return contextIsValid;
}