如何读取VPN登录名?

时间:2011-12-21 18:40:35

标签: c# login checkpoint

我们有一个应用程序需要用户连接到VPN才能运行。问题是我们依靠Windows身份验证来验证应用程序。但是,我们遇到了一些机器,其Windows登录名和AD登录名不同。

有人可以建议我们一直阅读AD登录名,这与VPN登录名一样吗? PS:我们使用checkpoint VPN Secure Client

1 个答案:

答案 0 :(得分:1)

如果你使用的是ActiveDirectory,你可以尝试这个,但我不确定你是否熟悉AD,但这对你来说是一个很好的学习工具,特别是如果有效的话。

static void Main(string[] args)
{
    string groupName = "Domain Users";
    string domainName = "";

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName);
    GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, groupName);

    if (grp != null)
    {
         foreach (Principal p in grp.GetMembers(false))
         {
                Console.WriteLine(p.SamAccountName + " - " + p.DisplayName);
         }

        grp.Dispose();
        ctx.Dispose();
        Console.ReadLine();
    }
    else
    {
        Console.WriteLine("\nWe did not find that group in that domain, perhaps the group resides in a different domain?");
        Console.ReadLine();
    }
}

或者您可以尝试How to get Users Belonging to Active Directory group

上此链接中指定的那个