【问题标题】:WPF Active Directory Calls performance issuesWPF Active Directory 调用性能问题
【发布时间】:2014-12-11 23:07:52
【问题描述】:

我有一个 C# WPF 应用程序,我正在尝试对 Active Directory Server 执行简单的检查,并且遇到了严重的性能问题,该功能需要 20-30 秒才能运行。使用相同的代码,我可以将它放在 Winforms 应用程序中,大约需要 1 秒或更短的时间。由于它是一个大广告,我猜它正在为最终用户提取所有属性,但我真的只想要这个人的名字和姓氏(用于其他目的),并确保用户在 Active Directory 中。

代码如下:

public string DomainUserNameGet(string ActiveDirectoryServer, string WindowsUserID) {
    /// queries AD to get logged on user's name
    string results = "";
    try {
    // create your domain context
    PrincipalContext oPrincipalContext = new PrincipalContext(
        ContextType.Domain
        , ActiveDirectoryServer
    );
    UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(
          oPrincipalContext
        , IdentityType.SamAccountName
        , ActiveDirectoryServer + @"\" + WindowsUserID                    
    );
    results =
        oUserPrincipal.GivenName.ToString()
        + " "
        + oUserPrincipal.Surname.ToString();
    } catch { }
    return results;
}

疯狂的是我可以通过命令行执行以下操作并在大约 1 秒内得到响应:

NET USER /DOMAIN LANID | find "LANID" /c

关于如何提高性能的任何想法?

【问题讨论】:

  • 为什么每次都创建主体上下文,肯定可以缓存?
  • 我无法想象 WPF 与 WinForms 有什么关系。一定有其他不同的地方。

标签: c# wpf performance optimization active-directory


【解决方案1】:

RenniePet 是对的;原来有一个DNS问题;我不确定为什么这会出现在 WPF vs. win 表单中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多