简体   繁体   English

C# Active Directory - 用户名和密码不正确,但详细信息实际上是正确的

[英]C# Active Directory - Incorrect Username and Password but details are actually correct

Issue with Active Directory & C#. Active Directory 和 C# 存在问题。 I'm getting an intermittent error stating that "The user name or password is incorrect.".我收到一个间歇性错误,指出“用户名或密码不正确。”。 However, I know the login details are correct as it works Locally in VS.但是,我知道登录详细信息是正确的,因为它在 VS 中本地工作。 It seemingly doesn't on the web server everytime.它似乎每次都不会出现在 web 服务器上。

Error:错误:

The user name or password is incorrect.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.DirectoryServices.DirectoryServicesCOMException: The user name or password is incorrect.

My code for storing the connection to the LDAP, bits hidden for security reasons:我用于存储与 LDAP 的连接的代码,出于安全原因隐藏了位:

    public static DirectoryEntry GetDirectoryEntryWithGc()
    {
        var de = new DirectoryEntry("GC://dc=TEXT,dc=TEXT,dc=TEXT");
        de.AuthenticationType = AuthenticationTypes.Secure;
        de.Username = "USERNAME";
        de.Password = "PASSWORD";
        return de;
    }

As mentioned, works Locally and is intermittent.如前所述,在本地工作并且是间歇性的。 Anyone any experience of this?有人有这方面的经验吗?

This is just a guess, but is there more than one domain in your AD forest?这只是一种猜测,但您的 AD 林中是否有多个域? And are you including the domain name in "USERNAME" (ie "DOMAIN\USERNAME" )?您是否在"USERNAME"中包含域名(即"DOMAIN\USERNAME" )?

Using GC:// without specifying a server name can connect to a server from any of the domains in your forest.在不指定服务器名称的情况下使用GC://可以从林中的任何域连接到服务器。 If you did not specify the domain name in your username, then it will assume the username is from the server's domain, which may not be the case.如果您没有在用户名中指定域名,那么它将假定用户名来自服务器的域,但情况可能并非如此。

If I'm correct in this, then you can solve the issue by including the domain name with the username:如果我在这方面是正确的,那么您可以通过在用户名中包含域名来解决问题:

de.Username = "DOMAIN\USERNAME";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Mobile C#是否针对Active Directory验证用户名和密码? - Windows mobile C# Validate a username and password against Active Directory? 如何在C#中使用用户名和密码在活动目录中找到用户及其所属的安全组? - How do I find a user and the security group they belong to in active directory with their username and password in C#? Active Directory-检查用户名/密码 - Active Directory - Check username / password 验证Active Directory用户名和密码 - Validating Active Directory username and password 在 C# 中创建密码为 Active Directory 的用户 - Creating Active Directory user with password in C# 使用Active Directory对用户进行身份验证,而不会在catch块内放置错误的用户名或密码错误 - Authenticating user with Active Directory without placing incorrect username or password error inside catch block 如何在C#中获取当前用户的Active Directory详细信息 - How to get the current user's Active Directory details in C# 如何使用 C# 中的 UserPrincipal 获取 Active Directory 中的地址详细信息 - How to get details of address in Active Directory using UserPrincipal in C# 如何从C#中的显示名称获取Active Directory中的用户名? - How to get a username in Active Directory from a display name in C#? 如何使用C#按用户名搜索Active Directory? - How can I search Active Directory by username using C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM