小编Szy*_*iga的帖子

ContextType.ApplicationDirectory中的AD LDS ValidateCredentials无法进行身份验证

我正在尝试在我的MVC应用程序中使用AD LDS进行用户身份验证.我设法写了一些代码,允许我创建/编辑/删除用户和组,但我似乎无法验证它们.这是我的示例代码:

using( var context = new PrincipalContext(ContextType.ApplicationDirectory, "Lenovo_T61-LapT",
                                    "CN=Kontrahenci,DC=TestApp,DC=local"))
{
    var userName = "avg.joe";
    var email = "avg.joe@smwhr.us";
    var password = "123456";
    var user = new UserPrincipal(context)
    {
        Name = userName,
        EmailAddress = email
    };
    user.SetPassword(password);
    user.Save();
    if (context.ValidateCredentials(userName , password, ContextOptions.SimpleBind))
        Console.WriteLine("Hooray!");

    user.Dispose();
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这永远不会得到"Writeline"只给出一个密码或用户名不正确的错误.

我玩过ContextOptions但没有任何运气.

有任何想法吗?

.net directoryservices adam active-directory lds

2
推荐指数
1
解决办法
6028
查看次数

如何围绕异步方法编写包装器?

我有一个JSON API,我希望我的应用程序访问.所以我写了一个方法.

public List<Books> GetBooks()
{
  var webclient = new WebClient();
  var jsonOutput = webclient.DownloadString(
                         new Uri("http://someplace.com/books.json")
                             );

  return ParseJSON(jsonOutput);//Some synchronous parsing method 
}
Run Code Online (Sandbox Code Playgroud)

现在我需要将DonwloadString更改为DownloadStringAsync.我找到了这个教程.

但这似乎太复杂了.我试图让这个工作,但我不确定这是否是正确的方法.也许有一种更简单,更好的方法?

c# events asynchronous webclient windows-phone-7

2
推荐指数
1
解决办法
1321
查看次数