小编Jab*_*ezz的帖子

Active Directory(LDAP) - 检查帐户被锁定/密码已过期

目前,我使用以下代码针对某些AD对用户进行身份验证:

DirectoryEntry entry = new DirectoryEntry(_path, username, pwd);

try
{
    // Bind to the native AdsObject to force authentication.
    Object obj = entry.NativeObject;

    DirectorySearcher search = new DirectorySearcher(entry) { 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
    _path = result.Path;
    _filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
    throw new Exception("Error authenticating user. " + ex.Message); …
Run Code Online (Sandbox Code Playgroud)

c# ldap active-directory

18
推荐指数
2
解决办法
5万
查看次数

如何动态构建LINQ

我有一个场景,我有自定义配置列名称,关联运算符,如<> =之间等,然后一个值相关联.

我正在尝试确定是否可以使用动态(字符串)where子句构建LINQ查询?

我注意到Predicate.OR Preditcate.AND的东西,但这不是我所说的.

有什么建议?

linq dynamic operators

8
推荐指数
2
解决办法
2万
查看次数

使用LINQ Dynamic Query Library和Dictionary <string,object>和.AsQueryable()

在我以前的关于使用LINQ动态建立字符串(WHERE子句)和使用它们的问题之一,我被引向LINQ动态查询库动态LINQ.

第一个问题是它只适用于IQueryable,但是这可以通过在任何IEnumerable上使用.AsQueryable()扩展方法来克服.

我遇到的问题是Dynamic LINQ在我的Dictionary上寻找一个名为"CustomerID"的属性(或者传递给动态linq的字符串谓词的任何东西).由于词典只有键和值,这显然不起作用.

因此,我认为我很聪明,我创建了一个扩展类: Dictionary<string, object>ICustomTypeDescriptor`.

这允许我覆盖GetProperties()类型.哪个好.我现在可以迭代Dictionary键并将它们添加到PropertyDescriptorCollection返回的内容中.

但后来我遇到了另一个问题.在整个Dynamic LINQ库中,它们使用"Expression instance",它只包含一个Type.但是对于我的CustomTypeDescriptor工作解决方案,我需要一个实际的Type实例,然后才能申请TypeDescriptor.GetProperties(instance, false).

所以得到实际的问题.考虑到上述所有信息,如果数据存储在具有键值对的字典中,如何将字符串格式"CustomerID = 1234 AND Quantity> = 10000"中的自定义where子句应用于LINQ查询.

我目前的解决方案是将数据转换为a DataTable并使用该.Select(query)方法.哪个有效,但我有兴趣寻找其他解决方案.特别是用于基准测试目的.

有任何想法吗?

c# linq dictionary types properties

6
推荐指数
1
解决办法
6043
查看次数

标签 统计

c# ×2

linq ×2

active-directory ×1

dictionary ×1

dynamic ×1

ldap ×1

operators ×1

properties ×1

types ×1