本文整理汇总了C#中DirectoryEntry类的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry类的具体用法?C# DirectoryEntry怎么用?C# DirectoryEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirectoryEntry类属于命名空间,在下文中一共展示了DirectoryEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AuthenticateUser
public bool AuthenticateUser(string Domain, string Username, string Password, string LDAP_Path, ref string Errmsg)
{
Errmsg = "";
string domainAndUsername = Domain + "\\" + Username;
DirectoryEntry entry = new DirectoryEntry(LDAP_Path, domainAndUsername, Password);
entry.AuthenticationType = AuthenticationTypes.Secure;
try
{
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + Username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (result == null)
{
return false;
}
// Update the new path to the user in the directory
LDAP_Path = result.Path;
string _filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
Errmsg = ex.Message;
return false;
throw new Exception("Error authenticating user." + ex.Message);
}
return true;
}
示例2: 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");
}
}
示例3: ADGroupListUpdate
public static int ADGroupListUpdate()
{
string file_location = HttpContext.Current.Server.MapPath("~") + "\\App_Data\\ADGroups.xml";
int GroupCount = 0;
DirectoryEntry dirEnt = new DirectoryEntry("LDAP://" + Utils.Settings.Get("domain_controller") );
string[] loadProps = new string[] { "name" };
XDocument xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
XElement root = new XElement("groups");
using (DirectorySearcher srch = new DirectorySearcher(dirEnt, "(objectClass=Group)", loadProps))
{
srch.PageSize = 6000;
var results = SafeFindAll(srch);
foreach (SearchResult sr in results)
{
XElement xe = new XElement("group", sr.Properties["name"][0].ToString());
root.Add(xe);
GroupCount++;
}
}
xDoc.Add(root);
if (File.Exists(file_location)) File.Delete(file_location);
xDoc.Save(file_location);
return GroupCount;
}
示例4: Build
public static void Build(DirectoryEntry rootEntry)
{
if (rootEntry.Members.Count > 0)
{
rootEntry.MembersTreeNodeDID = BuildStorageEntry(rootEntry);
}
}
示例5: AuthenticateUser
public bool AuthenticateUser(string domain, string username, string password, string LdapPath, out string Errmsg)
{
Errmsg = "";
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(LdapPath, domainAndUsername, password);
try
{
// Bind to the native AdsObject to force authentication.
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
// Update the new path to the user in the directory
LdapPath = result.Path;
string _filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
Errmsg = ex.Message;
return false;
throw new Exception("Error authenticating user." + ex.Message);
}
return true;
}
示例6: Login1_Authenticate
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://NTNIGE", Login1.UserName, Login1.Password);
try
{
object ent = entry.NativeObject;
e.Authenticated = true;
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
con.ConnectionString = ConfigurationManager.ConnectionStrings["nfte"].ConnectionString;
cmd.Connection = con;
cmd.CommandText = string.Format("select count(*) from nfte.users where userid = '{0}'", Login1.UserName.Trim());
con.Open();
object o = cmd.ExecuteScalar();
int usercount = Convert.ToInt32(o);
if (usercount > 0)
{
FormsAuthentication.SetAuthCookie(Login1.UserName, false);
}
else
{
e.Authenticated = false;
Login1.FailureText = "Your username or password is wrong,please check it and try again";
}
}
catch
{
e.Authenticated = false;
Login1.FailureText = "Internal error while trying to log in";
}
}
示例7: AddNode
/*
* AddNode - Recurses over some root DirectoryEntry node and add's text to the treeViewDirectory
* Returns - TreeNode created at current level of recursion
*/
public TreeNode AddNode(DirectoryEntry directoryNode, TreeNode rootNode)
{
TreeNode node = null;
if (rootNode == null)
{
node = new TreeNode(directoryNode.LongFilename == null ? directoryNode.ShortFilename : directoryNode.LongFilename);
}
else
{
node = new TreeNode(directoryNode.LongFilename == null ? directoryNode.ShortFilename : directoryNode.LongFilename);
rootNode.Nodes.Add(node);
}
if (directoryNode.IsDirectory || directoryNode.IsVolumeID)
{
foreach (DirectoryEntry entry in directoryNode.Children)
{
AddNode(entry, node);
}
}
else
{
node.Tag = directoryNode;
}
return node;
}
示例8: DirectoryRegistration
public void DirectoryRegistration(string name, int id)
{
DirectoryEntry wpis = new DirectoryEntry();
wpis.Id = id;
wpis.Name = name;
Directory.Add(name, wpis);
}
示例9: GetFullName
/// <summary>
///
/// </summary>
/// <param name="strLogin"></param>
/// <returns></returns>
public static string GetFullName(string strLogin)
{
string str = "";
string strDomain;
string strName; // Parse the string to check if domain name is present.
int idx = strLogin.IndexOf('\\');
if (idx == -1)
{
idx = strLogin.IndexOf('@');
}
if (idx != -1)
{
strDomain = strLogin.Substring(0, idx);
strName = strLogin.Substring(idx + 1);
}
else
{
strDomain = Environment.MachineName;
strName = strLogin;
}
DirectoryEntry obDirEntry = null;
try
{
obDirEntry = new DirectoryEntry("WinNT://" + strDomain + "/" + strName);
System.DirectoryServices.PropertyCollection coll = obDirEntry.Properties;
object obVal = coll["FullName"].Value;
str = obVal.ToString();
}
catch (Exception ex)
{
str = ex.Message;
}
return str;
}
示例10: IsAuthenticated
public bool IsAuthenticated(string domain, string username, string pwd)
{
if (username == "esb" && pwd == "a") return true;
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
try
{
//Bind to the native AdsObject to force authentication.
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
//Update the new path to the user in the directory.
_path = result.Path;
_filterAttribute = (string)result.Properties["cn"][0];
}
catch (System.Exception ex)
{
throw new System.Exception(" " + ex.Message);
}
return true;
}
示例11: BuildStorageEntry
private static int BuildStorageEntry(DirectoryEntry storageEntry)
{
// direct members of each storage are organised in a separate red-black tree
RedBlackTree<DirectoryEntry> rbTree = new RedBlackTree<DirectoryEntry>();
foreach (DirectoryEntry entry in storageEntry.Members.Values)
{
rbTree.Add(entry);
}
foreach (RedBlackTreeNode<DirectoryEntry> node in rbTree.InorderTreeWalk(rbTree.Root))
{
DirectoryEntry entry = node.Data;
entry.NodeColor = GetNodeColor(node.Color);
entry.LeftChildDID = GetNodeID(node.Left);
entry.RightChildDID = GetNodeID(node.Right);
if (entry.Members.Count > 0)
{
entry.EntryType = EntryType.Storage;
entry.MembersTreeNodeDID = BuildStorageEntry(entry);
}
else
{
entry.EntryType = EntryType.Stream;
entry.MembersTreeNodeDID = -1;
}
}
return rbTree.Root.Data.ID;
}
示例12: CopyNodeRecursively
/**
* Copies an Entry into a target POIFS directory, recursively
*/
public static void CopyNodeRecursively(Entry entry, DirectoryEntry target)
{
// System.err.println("copyNodeRecursively called with "+entry.GetName()+
// ","+tarGet.getName());
DirectoryEntry newTarget = null;
if (entry.IsDirectoryEntry)
{
newTarget = target.CreateDirectory(entry.Name);
IEnumerator entries = ((DirectoryEntry)entry).Entries;
while (entries.MoveNext())
{
CopyNodeRecursively((Entry)entries.Current, newTarget);
}
}
else
{
DocumentEntry dentry = (DocumentEntry)entry;
using (DocumentInputStream dstream = new DocumentInputStream(dentry))
{
target.CreateDocument(dentry.Name, dstream);
//now part of usings call to Dispose: dstream.Close();
}
}
}
示例13: CopyNodeRecursively
/**
* Copies an Entry into a target POIFS directory, recursively
*/
public static void CopyNodeRecursively(Entry entry, DirectoryEntry target)
{
// System.err.println("copyNodeRecursively called with "+entry.getName()+
// ","+target.getName());
DirectoryEntry newTarget = null;
if (entry.IsDirectoryEntry)
{
DirectoryEntry dirEntry = (DirectoryEntry)entry;
newTarget = target.CreateDirectory(entry.Name);
newTarget.StorageClsid=(dirEntry.StorageClsid);
IEnumerator<Entry> entries = dirEntry.Entries;
while (entries.MoveNext())
{
CopyNodeRecursively((Entry)entries.Current, newTarget);
}
}
else
{
DocumentEntry dentry = (DocumentEntry)entry;
DocumentInputStream dstream = new DocumentInputStream(dentry);
target.CreateDocument(dentry.Name, dstream);
dstream.Close();
}
}
示例14: CorHeader
public CorHeader(
CorFlags flags,
DirectoryEntry metadataDirectory,
int entryPointTokenOrRelativeVirtualAddress = 0,
ushort majorRuntimeVersion = 2,
ushort minorRuntimeVersion = 5,
DirectoryEntry resourcesDirectory = default(DirectoryEntry),
DirectoryEntry strongNameSignatureDirectory = default(DirectoryEntry),
DirectoryEntry codeManagerTableDirectory = default(DirectoryEntry),
DirectoryEntry vtableFixupsDirectory = default(DirectoryEntry),
DirectoryEntry exportAddressTableJumpsDirectory = default(DirectoryEntry),
DirectoryEntry managedNativeHeaderDirectory = default(DirectoryEntry))
{
MajorRuntimeVersion = majorRuntimeVersion;
MinorRuntimeVersion = minorRuntimeVersion;
MetadataDirectory = metadataDirectory;
Flags = flags;
EntryPointTokenOrRelativeVirtualAddress = entryPointTokenOrRelativeVirtualAddress;
ResourcesDirectory = resourcesDirectory;
StrongNameSignatureDirectory = strongNameSignatureDirectory;
CodeManagerTableDirectory = codeManagerTableDirectory;
VtableFixupsDirectory = vtableFixupsDirectory;
ExportAddressTableJumpsDirectory = exportAddressTableJumpsDirectory;
ManagedNativeHeaderDirectory = managedNativeHeaderDirectory;
}
示例15: Resolve
/// <summary>
/// Performs a path lookup obeying to the passed flags.
/// </summary>
/// <param name="rootDirectory">The root directory.</param>
/// <param name="path">The path to resolve.</param>
/// <param name="flags">Controls aspects of the path lookup process.</param>
/// <returns>
/// The directory entry of the resolved path.
/// </returns>
/// <remarks>
/// This call my result in other exceptions not specified in the above list. Other exceptions can be thrown by IVfsNode implementations, which are visited during the traversal
/// process. For example a network file system node may throw an exception, if the server is unreachable.
/// </remarks>
public static DirectoryEntry Resolve(DirectoryEntry rootDirectory, ref string path, PathResolutionFlags flags)
{
// FIXME: Get the root from the thread execution block
DirectoryEntry current = rootDirectory;
PathResolver resolver = new PathResolver(rootDirectory, current);
return resolver.Resolve(ref path, flags);
}