小编Bha*_*dar的帖子

在C#中使用VPN进行Active Directory身份验证

我正在开发一个Web应用程序,可以根据Active Directory服务器对用户进行身份验证。现在,如果我在该AD服务器所在的域中从开发PC运行我的代码,则我的代码可以平稳运行。我们需要使用VPN从完全不同的网络中运行代码,并且开发PC不在该AD中。尝试访问AD服务器时出现以下错误。

指定的域不存在或无法联系。

我的VPN运行正常。我可以使用此VPN访问远程桌面。我知道需要一些调整才能解决问题,但找不到它。我经过以下链接,但找不到任何解决方案。

  1. 通过VPN从.NET客户端进行域身份验证

  2. 如何在Windows窗体应用程序中获取VPN用户的当前用户身份?

以下是我在中的设置 web.config

<appSettings>
   <add key="LDAPPath" value="LDAP://DC=MYSERVER,DC=COM" />
   <add key="ADGroupName" value="Analyst"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)

这是我的代码

public class LdapAuthentication
{
    private string _path;
    private string _filterAttribute;

    public LdapAuthentication()
    {
        _path = System.Configuration.ConfigurationManager.AppSettings["LDAPPath"].ToString();
    }

    public bool IsAuthenticated(string username, string pwd)
    {
        try
        {
            DirectoryEntry entry = new DirectoryEntry(_path, username, pwd);

            entry.Path = _path;
            entry.Username = username;
            entry.Password = pwd;

            // Bind to the native AdsObject to force authentication.
            object obj = entry.NativeObject;

            DirectorySearcher search = new DirectorySearcher(entry);

            search.Filter = …
Run Code Online (Sandbox Code Playgroud)

c# vpn active-directory

5
推荐指数
1
解决办法
1491
查看次数

标签 统计

active-directory ×1

c# ×1

vpn ×1