本文整理汇总了C#中DirectoryEntry类的典型用法代码示例。如果您正苦于以下问题:C# DirectoryEntry类的具体用法?C# DirectoryEntry怎么用?C# DirectoryEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirectoryEntry类属于命名空间,在下文中一共展示了DirectoryEntry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:TIT-tech,项目名称:OPM_BO,代码行数:34,代码来源:GenericLib.cs
示例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");
}
}
开发者ID:JeremyMorgan,项目名称:csharpworkshop,代码行数:33,代码来源:CommandLineAD.cs
示例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;
}
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:29,代码来源:utils.cs
示例4: Build
public static void Build(DirectoryEntry rootEntry)
{
if (rootEntry.Members.Count > 0)
{
rootEntry.MembersTreeNodeDID = BuildStorageEntry(rootEntry);
}
}
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:7,代码来源:DirectoryTree.cs
示例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;
}
开发者ID:chenx,项目名称:Ci40_1,代码行数:33,代码来源:Login.aspx.cs
示例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";
}
}
开发者ID:kanke,项目名称:Outsourced-Non-FTEs,代码行数:35,代码来源:Login.aspx.cs
示例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;
}
开发者ID:arbiter34,项目名称:FATExplorer,代码行数:30,代码来源:FATExplorer.cs
示例8: DirectoryRegistration
public void DirectoryRegistration(string name, int id)
{
DirectoryEntry wpis = new DirectoryEntry();
wpis.Id = id;
wpis.Name = name;
Directory.Add(name, wpis);
}
开发者ID:sopel30,项目名称:tsst2,代码行数:7,代码来源:NCC.cs
示例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;
}
开发者ID:shukla2009,项目名称:Personal,代码行数:40,代码来源:DTCvsFlashMain.master.cs
示例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;
}
开发者ID:vebin,项目名称:soa,代码行数:34,代码来源:ADAuthen.cs
示例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;
}
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:30,代码来源:DirectoryTree.cs
示例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();
}
}
}
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:29,代码来源:POIUtils.cs
示例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();
}
}
开发者ID:Reinakumiko,项目名称:npoi,代码行数:28,代码来源:EntryUtils.cs
示例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;
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:25,代码来源:CorHeader.cs
示例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);
}
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:20,代码来源:PathResolver.cs
示例16: BindUser
int UserId; // For User Id
#endregion Fields
#region Methods
/// <summary>
/// To bind active directory records in user details grid
/// </summary>
public void BindUser()
{
DataTable DtBindUser = new DataTable();
DataColumn Dtmail = new DataColumn("mail");
DataColumn Dtfname = new DataColumn("fname");
DataColumn Dtlname = new DataColumn("lname");
DataColumn DtdisplayName = new DataColumn("displayName");
DtBindUser.Columns.Add(Dtmail);
DtBindUser.Columns.Add(Dtfname);
DtBindUser.Columns.Add(Dtlname);
DtBindUser.Columns.Add(DtdisplayName);
DataRow Druser;
// Added connection string for active directory user
string connection = ConfigurationManager.ConnectionStrings["ADConnection"].ToString();
DirectorySearcher DsSearch = new DirectorySearcher(connection);
// declaired domain from which you want to fetch active directory users
DirectoryEntry UserDomain = new DirectoryEntry("LDAP://DC=kpmg,DC=aptaracorp,DC=com");
DirectorySearcher Usersearch = new DirectorySearcher(connection);
DsSearch.SearchRoot = UserDomain;
DsSearch.SearchScope = SearchScope.Subtree;
SearchResultCollection UserResult;
//Applied Filter On User For Specific Fname and Lname
Usersearch.Filter = "(&(objectClass=user)(sn=" + txtLastName.Text + "*)(givenName=" + txtFName.Text + "*))";
UserResult = Usersearch.FindAll();
for (int i = 0; i < UserResult.Count; i++)
{
string AccounName = UserResult[i].Properties["samaccountname"][0].ToString();
DirectorySearcher DrSearcher = new System.DirectoryServices.DirectorySearcher("(samaccountname=" + AccounName + ")");
SearchResult SrchRes = DrSearcher.FindOne();
DirectoryEntry DrEntry = SrchRes.GetDirectoryEntry();
try
{
if (DrEntry.Properties["givenName"][0].ToString() != "")
{
string FirstName = DrEntry.Properties["givenName"][0].ToString();
string LastName = DrEntry.Properties["sn"][0].ToString();
string UserEmail = DrEntry.Properties["mail"][0].ToString();
string UserDisName = DrEntry.Properties["displayName"][0].ToString();
Druser = DtBindUser.NewRow();
Druser["mail"] = UserEmail.ToString();
Druser["fname"] = FirstName.ToString();
Druser["lname"] = LastName.ToString();
Druser["displayName"] = UserDisName.ToString();
DtBindUser.Rows.Add(Druser);
}
}
catch
{
////throw;
}
}
if (DtBindUser.Rows.Count > 0)
{
grdUserDetails.DataSource = DtBindUser;
grdUserDetails.DataBind();
}
}
开发者ID:kamleshdaxini,项目名称:LocalDevelopment,代码行数:69,代码来源:UserDetails.aspx.cs
示例17: doADCopy
private void doADCopy(String username)
{
DirectoryEntry de = new DirectoryEntry("LDAP://ewprint.eastway.local/OU=Active Users,DC=eastway,DC=local");
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = "sAMAccountName=" + username;
SearchResult sr = ds.FindOne();
DirectoryEntry user = sr.GetDirectoryEntry();
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["EWEHR"].ToString());
try {
cn.Open();
if (isEchartsUser(user.Properties["employeeNumber"].Value.ToString())) {
SqlCommand cmd = new SqlCommand("UPDATE echarts_user set " +
"office = '" + user.Properties["physicalDeliveryOfficeName"].Value + "', " +
"office_phone = '" + user.Properties["telephoneNumber"].Value + "', " +
"staff_description = '" + user.Properties["title"].Value + "', " +
"staff_name = '" + user.Properties["displayName"].Value + "', " +
"status = 'Active', " +
"supervisor = '" + getManager(user.Properties["manager"].Value.ToString()) + "', " +
"username = '" + user.Properties["cn"].Value + "' " +
"WHERE staff_id = '" + user.Properties["employeeNumber"].Value + "'", cn);
if (cmd.ExecuteNonQuery() == 0) {
Response.Write("UPDATE FAILED");
} else {
HttpCookie staffid = new HttpCookie("staff_id");
staffid.Value = (String)user.Properties["employeeNumber"].Value;
staffid.Expires = DateTime.UtcNow.AddMonths(6);
staffid.Domain = EchartsAuth.domainName;
Response.Cookies.Add(staffid);
doRedirect(Request.QueryString["continue"]);
}
} else {
SqlCommand cmd = new SqlCommand("INSERT INTO echarts_user " +
"(username,office,office_phone,staff_description,staff_id,staff_name,status,supervisor) " +
"VALUES('" + username + "','" +
user.Properties["physicalDeliveryOfficeName"].Value + "','" +
user.Properties["telephoneNumber"].Value + "','" +
user.Properties["title"].Value + "','" +
user.Properties["employeeNumber"].Value + "','" +
user.Properties["displayName"].Value + "','" +
"Active" + "','" +
getManager(user.Properties["manager"].Value.ToString()) + "')", cn);
if (cmd.ExecuteNonQuery() == 0) {
Response.Write("INSERT FAILED");
} else {
HttpCookie staffid = new HttpCookie("staff_id");
staffid.Value = (String)user.Properties["employeeNumber"].Value;
staffid.Expires = DateTime.UtcNow.AddMonths(6);
staffid.Domain = EchartsAuth.domainName;
Response.Cookies.Add(staffid);
HttpCookie firstLogin = new HttpCookie("first_login");
firstLogin.Domain = EchartsAuth.domainName;
Response.Cookies.Add(firstLogin);
doRedirect(Request.QueryString["continue"]);
}
}
} finally {
cn.Close();
}
}
开发者ID:ihilt,项目名称:echarts-dotnetlogon,代码行数:59,代码来源:login.aspx.cs
示例18: CopyNodes
/**
* Copies all the nodes from one POIFS Directory to another
*
* @param sourceRoot
* is the source Directory to copy from
* @param targetRoot
* is the target Directory to copy to
*/
public static void CopyNodes(DirectoryEntry sourceRoot,
DirectoryEntry targetRoot)
{
foreach (Entry entry in sourceRoot)
{
CopyNodeRecursively(entry, targetRoot);
}
}
开发者ID:Reinakumiko,项目名称:npoi,代码行数:16,代码来源:EntryUtils.cs
示例19: RangeRetriever
///
/// <summary>
/// Creates a new RangeRetriever object.
/// </summary>
/// <param name="de">DirectoryEntry object whose attribute needs to be range retrieved</param>
/// <param name="propertyName">name of the attribute that needs to be range retrieved, ex: "memberOf"</param>
/// <param name="disposeDirEntry">
/// If set to true, the supplied DirectoryEntry will be diposed,
/// by this object's Dispose() method
/// </param>
///
public RangeRetriever(DirectoryEntry de, string propertyName, bool disposeDirEntry)
{
GlobalDebug.WriteLineIf(GlobalDebug.Info, "RangeRetriever", "RangeRetriever: de.Path={0}, propertyName={1}", de.Path, propertyName);
_de = de;
_propertyName = propertyName;
_disposeDirEntry = disposeDirEntry;
}
开发者ID:chcosta,项目名称:corefx,代码行数:19,代码来源:RangeRetriever.cs
示例20: CheckUserAuthentication
public bool CheckUserAuthentication(String userAccount)
{
//DirectoryEntry entry = new DirectoryEntry(LDAPConnString);
DirectoryEntry entry = new DirectoryEntry(lDAPConnString, userName, password);
//Change the domain name to match the target domain
String account = userAccount;
//string group = "AdminGroup";
try
{
//Search Actived Directory for the username used during login and generate list of groups the user is a member of
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + account + ")";
search.PropertiesToLoad.Add("memberOf");
SearchResult result = search.FindOne();
//Search Active Directory for the group specified in the authorizedGroup variable and list the group's members.
DirectorySearcher groupSearch = new DirectorySearcher(entry);
groupSearch.Filter = "(SAMAccountName=" + authorizedGroup + ")";
groupSearch.PropertiesToLoad.Add("member");
SearchResult groupResult = groupSearch.FindOne();
//Compare groups the user is a member of with the specified group. If a match, return true to the calling aspx page.
if (result != null)
{
int allGroupCount = result.Properties["memberOf"].Count;
int checkGroupCount = groupResult.Properties["member"].Count;
for (int i = 0; i < allGroupCount; i++)
{
string number = lDAPContextString + result.Properties["memberOf"][i].ToString();
for (int j = 0; j < checkGroupCount; j++)
{
string grp = groupResult.Path[j].ToString();
string usr = result.Path.ToString();
if (number == groupResult.Path.ToString())
{
return true;
}
}
}
}
else
{
return false;
}
}
catch (Exception ex)
{
string debug = ex.Message;
return false;
}
return false;
}
开发者ID:UFRA-UVU,项目名称:WebDev,代码行数:58,代码来源:ADAuthStrings.cs
注:本文中的DirectoryEntry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论