C# Active Directory - 用户名和密码不正确,但详细信息实际上是正确的 [英] C# Active Directory - Incorrect Username and Password but details are actually correct

查看:30
本文介绍了C# Active Directory - 用户名和密码不正确,但详细信息实际上是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Active Directory 的问题 &C#.我收到一个间歇性错误,指出用户名或密码不正确.".但是,我知道登录详细信息是正确的,因为它在 VS 中本地工作.它似乎不是每次都在 Web 服务器上.

Issue with 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. It seemingly doesn't on the web server everytime.

错误:

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.

我用于存储与 LDAP 连接的代码,出于安全原因隐藏了位:

My code for storing the connection to the LDAP, bits hidden for security reasons:

    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?

推荐答案

这只是一种猜测,但您的 AD 林中是否有多个域?您是否在 "USERNAME" 中包含了域名(即 "DOMAIN\USERNAME")?

This is just a guess, but is there more than one domain in your AD forest? And are you including the domain name in "USERNAME" (i.e. "DOMAIN\USERNAME")?

使用 GC:// 而不指定服务器名称可以从您的林中的任何域连接到服务器.如果您没有在用户名中指定域名,那么它会假设用户名来自服务器的域,但事实可能并非如此.

Using GC:// without specifying a server name can connect to a server from any of the domains in your forest. 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";

这篇关于C# Active Directory - 用户名和密码不正确,但详细信息实际上是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆