Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 416511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:29:16+00:00 2026-05-12T18:29:16+00:00

Microsoft has a general purpose KB article ( Q316748 ) describing how to authenticate

  • 0

Microsoft has a general purpose KB article (Q316748) describing how to authenticate against Active Directory using the DirectoryEntry object. In their example they produce a username value by concatenating the domain name and username into the standard NetBIOS format(“domain\username”) and passing that as a parameter to the directory entry constructor:

string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

It recently came to our attention that the domain part of the username was being completely ignored and in multiple environments I’ve confirmed this behavior. The username and password are in fact being used, as authentication fails when they’re invalid, but any arbitrary value can be supplied for the domain name and authentication passes. At a glance I’d theorize this format works for WinNT based directory access but the domain part is ignored for LDAP.

A check on google shows many LDAP examples passing a “domain\username” value to the DirectoryEntry object so I’ve either messed something up in my configuration or there’s a lot of people confused by the KB article. Can anyone confirm this is the expected behavior or recommend a way to accept “domain\username” values and authenticate against Active Directory with them?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:29:16+00:00Added an answer on May 12, 2026 at 6:29 pm

    The short answer: When the path parameter of the DirectoryEntry constructor contains an invalid domain name the DirectoryEntry object will (after an unsuccessful search for the invalid domain in the forrest) attempt a fall back by dropping the domain part of the username parameter and attempt connection using the plain username (sAMAccountName).

    The long answer: If the domain name specified in the username parameter is invalid but the user exists in the domain specified in the path parameter the user will be authenticated (through the use of the fallback). However, if the user exists in another domain in the forrest than the one specified in the path parameter authentication will only succeed when the domain part of the username parameter is included and correct.

    There are four different ways of specifying the username parameter when dealing with DirectoryEntry-objects:

    • Distinguished Name (CN=Username,CN=Users,DC=domain,DC=local)
    • NT Account Name (DOMAIN\Username)
    • Plain Account Name/sAMAccountname (username)
    • User Principal Name (generally username@domain.local)

    Let me illustrate with an example:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using System.DirectoryServices;
    
    namespace DirectoryTest
    {
      class Program
      {
    
        private static Int32 counter = 1;
    
        static void Main(string[] args)
        {
          TestConnection();
        }
    
        private static void TestConnection()
        {
          String domainOne = "LDAP://DC=domain,DC=one";
          String domainOneName = "DOMAINONE";
          String domainOneUser = "onetest";
          String domainOnePass = "testingONE!";
    
          String domainTwo = "LDAP://DC=domain,DC=two";
          String domainTwoName = "DOMAINTWO";
          String domainTwoUser = "twotest";
          String domainTwoPass = "testingTWO!";
    
          String invalidDomain = "INVALIDDOMAIN";
    
          // 1) This works because it's the correct NT Account Name in the same domain:
          Connect(domainOne, domainOneName + "\\" + domainOneUser, domainOnePass);
    
          // 2) This works because username can be supplied without the domain part
          // (plain username = sAMAccountName):
          Connect(domainOne, domainOneUser, domainOnePass);
    
          // 3) This works because there's a fall back in DirectoryEntry to drop the domain part
          // and attempt connection using the plain username (sAMAccountName) in (in this case)
          // the forrest root domain:
          Connect(domainOne, invalidDomain + "\\" + domainOneUser, domainOnePass);
    
          // 4) This works because the forrest is searched for a domain matching domainTwoName:
          Connect(domainOne, domainTwoName + "\\" + domainTwoUser, domainTwoPass);
    
          // 5) This fails because domainTwoUser is not in the forrest root (domainOne)
          // and because no domain was specified other domains are not searched:
          Connect(domainOne, domainTwoUser, domainTwoPass);
    
          // 6) This fails as well because the fallback of dropping the domain name and using
          // the plain username fails (there's no domainTwoUser in domainOne):
          Connect(domainOne, invalidDomain + "\\" + domainTwoUser, domainTwoPass);
    
          // 7) This fails because there's no domainTwoUser in domainOneName:
          Connect(domainOne, domainOneName + "\\" + domainTwoUser, domainTwoPass);
    
          // 8) This works because there's a domainTwoUser in domainTwoName:
          Connect(domainTwo, domainTwoName + "\\" + domainTwoUser, domainTwoPass);
    
          // 9) This works because of the fallback to using plain username when connecting
          // to domainTwo with an invalid domain name but using domainTwoUser/Pass:
          Connect(domainTwo, invalidDomain + "\\" + domainTwoUser, domainTwoPass);
        }
    
        private static void Connect(String path, String username, String password)
        {
          Console.WriteLine(
            "{0}) Path: {1} User: {2} Pass: {3}",
            counter, path, username, password);
          DirectoryEntry de = new DirectoryEntry(path, username, password);
          try
          {
            de.RefreshCache();
            Console.WriteLine("{0} = {1}", username, "Autenticated");
          }
          catch (Exception ex)
          {
            Console.WriteLine("{0} ({1})", ex.Message, username);
          }
          Console.WriteLine();
          counter++;
        }
      }
    }
    

    In the example above domain.one is the forrest root domain and domain.two is in the same forrest as domain.one (but a different tree naturally).

    So to answer your question: Authentication will always fail if the user in not in the domain that we’re connecting to and no or an invalid domain name is specified in the username parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 290k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to generate html using javascript, then you… May 13, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer This is probably just a timeout issue. It's taking much… May 13, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer The standard C++ approach is to mandate that the type(s)… May 13, 2026 at 5:42 pm

Related Questions

In general, I design classes in such a manner as to not require access
I am using Delphi, but this is a simple and general problem: I'm doing
I've been a big fan of MediaWiki and similar wiki-based text editors. I like
I've recently started a new project, and we plan to create this in Silverlight.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.