本文整理汇总了C#中System.DirectoryServices.ActiveDirectory.DirectoryContext.isDomain方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryContext.isDomain方法的具体用法?C# DirectoryContext.isDomain怎么用?C# DirectoryContext.isDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DirectoryServices.ActiveDirectory.DirectoryContext
的用法示例。
在下文中一共展示了DirectoryContext.isDomain方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDomain
public static Domain GetDomain(DirectoryContext context)
{
if (context != null)
{
if (context.ContextType == DirectoryContextType.Domain || context.ContextType == DirectoryContextType.DirectoryServer)
{
if (context.Name != null || context.isDomain())
{
if (context.Name == null || context.isDomain() || context.isServer())
{
context = new DirectoryContext(context);
DirectoryEntryManager directoryEntryManager = new DirectoryEntryManager(context);
string propertyValue = null;
try
{
DirectoryEntry cachedDirectoryEntry = directoryEntryManager.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
if (!context.isServer() || Utils.CheckCapability(cachedDirectoryEntry, Capability.ActiveDirectory))
{
propertyValue = (string)PropertyManager.GetPropertyValue(context, cachedDirectoryEntry, PropertyManager.DefaultNamingContext);
}
else
{
object[] name = new object[1];
name[0] = context.Name;
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", name), typeof(Domain), null);
}
}
catch (COMException cOMException1)
{
COMException cOMException = cOMException1;
int errorCode = cOMException.ErrorCode;
if (errorCode != -2147016646)
{
throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
}
else
{
if (context.ContextType != DirectoryContextType.Domain)
{
object[] objArray = new object[1];
objArray[0] = context.Name;
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", objArray), typeof(Domain), null);
}
else
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DomainNotFound"), typeof(Domain), context.Name);
}
}
}
return new Domain(context, Utils.GetDnsNameFromDN(propertyValue), directoryEntryManager);
}
else
{
if (context.ContextType != DirectoryContextType.Domain)
{
object[] name1 = new object[1];
name1[0] = context.Name;
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", name1), typeof(Domain), null);
}
else
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DomainNotFound"), typeof(Domain), context.Name);
}
}
}
else
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ContextNotAssociatedWithDomain"), typeof(Domain), null);
}
}
else
{
throw new ArgumentException(Res.GetString("TargetShouldBeServerORDomain"), "context");
}
}
else
{
throw new ArgumentNullException("context");
}
}
示例2: GetDomain
public static Domain GetDomain(DirectoryContext context)
{
// check that the argument is not null
if (context == null)
throw new ArgumentNullException("context");
// contexttype should be Domain or DirectoryServer
if ((context.ContextType != DirectoryContextType.Domain) &&
(context.ContextType != DirectoryContextType.DirectoryServer))
{
throw new ArgumentException(Res.GetString(Res.TargetShouldBeServerORDomain), "context");
}
if ((context.Name == null) && (!context.isDomain()))
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.ContextNotAssociatedWithDomain), typeof(Domain), null);
}
if (context.Name != null)
{
// the target should be a valid domain name or a server
if (!((context.isDomain()) || (context.isServer())))
{
if (context.ContextType == DirectoryContextType.Domain)
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DomainNotFound), typeof(Domain), context.Name);
}
else
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DCNotFound, context.Name), typeof(Domain), null);
}
}
}
// work with copy of the context
context = new DirectoryContext(context);
// bind to the rootDSE of the domain specified in the context
// and get the dns name
DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context);
DirectoryEntry rootDSE = null;
string defaultDomainNC = null;
try
{
rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
if ((context.isServer()) && (!Utils.CheckCapability(rootDSE, Capability.ActiveDirectory)))
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DCNotFound, context.Name), typeof(Domain), null);
}
defaultDomainNC = (string)PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DefaultNamingContext);
}
catch (COMException e)
{
int errorCode = e.ErrorCode;
if (errorCode == unchecked((int)0x8007203a))
{
if (context.ContextType == DirectoryContextType.Domain)
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DomainNotFound), typeof(Domain), context.Name);
}
else
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DCNotFound, context.Name), typeof(Domain), null);
}
}
else
{
throw ExceptionHelper.GetExceptionFromCOMException(context, e);
}
}
// return domain object
return new Domain(context, Utils.GetDnsNameFromDN(defaultDomainNC), directoryEntryMgr);
}
示例3: GetPolicyServerName
internal static string GetPolicyServerName(DirectoryContext context, bool isForest, bool needPdc, string source)
{
string name;
PrivateLocatorFlags privateLocatorFlag = PrivateLocatorFlags.DirectoryServicesRequired;
if (!context.isDomain())
{
if (!isForest)
{
name = context.Name;
}
else
{
if (!needPdc)
{
if (context.ContextType != DirectoryContextType.DirectoryServer)
{
name = Locator.GetDomainControllerInfo(null, source, null, (long)privateLocatorFlag).DomainControllerName.Substring(2);
}
else
{
DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.DefaultNamingContext);
string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.RootDomainNamingContext);
if (Utils.Compare(propertyValue, str) != 0)
{
name = Locator.GetDomainControllerInfo(null, source, null, (long)privateLocatorFlag).DomainControllerName.Substring(2);
}
else
{
name = context.Name;
}
}
}
else
{
privateLocatorFlag = privateLocatorFlag | PrivateLocatorFlags.PdcRequired;
name = Locator.GetDomainControllerInfo(null, source, null, (long)privateLocatorFlag).DomainControllerName.Substring(2);
}
}
}
else
{
if (needPdc)
{
privateLocatorFlag = privateLocatorFlag | PrivateLocatorFlags.PdcRequired;
}
name = Locator.GetDomainControllerInfo(null, source, null, (long)privateLocatorFlag).DomainControllerName.Substring(2);
}
return name;
}
示例4: GetDomain
public static Domain GetDomain(DirectoryContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if ((context.ContextType != DirectoryContextType.Domain) && (context.ContextType != DirectoryContextType.DirectoryServer))
{
throw new ArgumentException(Res.GetString("TargetShouldBeServerORDomain"), "context");
}
if ((context.Name == null) && !context.isDomain())
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ContextNotAssociatedWithDomain"), typeof(Domain), null);
}
if (((context.Name != null) && !context.isDomain()) && !context.isServer())
{
if (context.ContextType == DirectoryContextType.Domain)
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DomainNotFound"), typeof(Domain), context.Name);
}
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", new object[] { context.Name }), typeof(Domain), null);
}
context = new DirectoryContext(context);
DirectoryEntryManager directoryEntryMgr = new DirectoryEntryManager(context);
DirectoryEntry rootDSE = null;
string distinguishedName = null;
try
{
rootDSE = directoryEntryMgr.GetCachedDirectoryEntry(WellKnownDN.RootDSE);
if (context.isServer() && !Utils.CheckCapability(rootDSE, Capability.ActiveDirectory))
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", new object[] { context.Name }), typeof(Domain), null);
}
distinguishedName = (string) PropertyManager.GetPropertyValue(context, rootDSE, PropertyManager.DefaultNamingContext);
}
catch (COMException exception)
{
if (exception.ErrorCode != -2147016646)
{
throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
}
if (context.ContextType == DirectoryContextType.Domain)
{
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DomainNotFound"), typeof(Domain), context.Name);
}
throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DCNotFound", new object[] { context.Name }), typeof(Domain), null);
}
return new Domain(context, Utils.GetDnsNameFromDN(distinguishedName), directoryEntryMgr);
}
示例5: GetPolicyServerName
internal static string GetPolicyServerName(DirectoryContext context, bool isForest, bool needPdc, string source)
{
PrivateLocatorFlags directoryServicesRequired = PrivateLocatorFlags.DirectoryServicesRequired;
if (context.isDomain())
{
if (needPdc)
{
directoryServicesRequired |= PrivateLocatorFlags.PdcRequired;
}
return Locator.GetDomainControllerInfo(null, source, null, (long) directoryServicesRequired).DomainControllerName.Substring(2);
}
if (isForest)
{
if (needPdc)
{
directoryServicesRequired |= PrivateLocatorFlags.PdcRequired;
return Locator.GetDomainControllerInfo(null, source, null, (long) directoryServicesRequired).DomainControllerName.Substring(2);
}
if (context.ContextType == DirectoryContextType.DirectoryServer)
{
DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
string str2 = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.DefaultNamingContext);
string str3 = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.RootDomainNamingContext);
if (Compare(str2, str3) == 0)
{
return context.Name;
}
return Locator.GetDomainControllerInfo(null, source, null, (long) directoryServicesRequired).DomainControllerName.Substring(2);
}
return Locator.GetDomainControllerInfo(null, source, null, (long) directoryServicesRequired).DomainControllerName.Substring(2);
}
return context.Name;
}
示例6: GetPolicyServerName
internal static string GetPolicyServerName(DirectoryContext context, bool isForest, bool needPdc, string source)
{
string serverName = null;
PrivateLocatorFlags flag = PrivateLocatorFlags.DirectoryServicesRequired;
// passes in either domain or forest name, just find the dc
if (context.isDomain())
{
if (needPdc)
{
flag |= PrivateLocatorFlags.PdcRequired;
}
serverName = Locator.GetDomainControllerInfo(null, source, null, (long)flag).DomainControllerName.Substring(2);
}
else
{
// user could pass in non-root domain server name in the context, so need to find a dc in root domain
if (isForest)
{
if (needPdc)
{
flag |= PrivateLocatorFlags.PdcRequired;
serverName = Locator.GetDomainControllerInfo(null, source, null, (long)flag).DomainControllerName.Substring(2);
}
else
{
if (context.ContextType == DirectoryContextType.DirectoryServer)
{
// need first to decide whether this is a server in the root domain or not
DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
string namingContext = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.DefaultNamingContext);
string rootNamingContext = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.RootDomainNamingContext);
if (Compare(namingContext, rootNamingContext) == 0)
{
serverName = context.Name;
}
else
{
// it is not a server in the root domain, so we need to do dc location
serverName = Locator.GetDomainControllerInfo(null, source, null, (long)flag).DomainControllerName.Substring(2);
}
}
else
{
serverName = Locator.GetDomainControllerInfo(null, source, null, (long)flag).DomainControllerName.Substring(2);
}
}
}
else
{
serverName = context.Name;
}
}
return serverName;
}