How can I make connection string for LDAP by two attributes DC=intechww,DC=com

I am pretty much new to the LDAP connection to a remote server Active Directory. My system administrator has provided me just two things. “DC=intechww,DC=com” I have network administrator username and password and so far I have tried many combination but not getting my response from the network.

I need to validate user credentials if user exist in Active directory then get his username and other details and store in my ASP.NET MVC app database.

My connection string for LDAP is:

<connectionStrings>
    <add name="ADConnectionString" 
         connectionString="LDAP://intechww.com/DC=users,DC=com" />
</connectionStrings>

Other Web.config details are

<system.web>
    <authentication mode="Forms">
        <forms name=".ADAuthCookie" loginUrl="~/User/Verify" timeout="15" slidingExpiration="false" protection="All" />
    </authentication>
    <membership defaultProvider="MY_ADMembershipProvider">
        <providers>
            <clear />
            <add name="MY_ADMembershipProvider" 
                 type="System.Web.Security.ActiveDirectoryMembershipProvider" 
                 connectionStringName="ADConnectionString" 
                 attributeMapUsername="sAMAccountName" 
                 connectionUsername="ServiceAccount" 
                 connectionPassword="********* " />
        </providers>
    </membership>
</system.web>

My C# controller method is:

[HttpPost]
public ActionResult Verify(User model)
{
    if (Membership.ValidateUser(model.username, model.password))
    {
        FormsAuthentication.SetAuthCookie(model.username, true);
    }
    else
    {
        ModelState.AddModelError("", "The user name or password provided is incorrect");
    }

    return View();
}

Upvotes: 1

Views: 1375

Answers (1)

marc_s
marc_s

Reputation: 754468

The DC= parts are the domain components that make up your LDAP name.

So given the inputs you've received, I'd try the following connection strings:

LDAP://intechww.com/DC=intechww,DC=com

This would connect to the root of the domain.

Or:

LDAP://intechww.com/CN=Users,DC=intechww,DC=com

This would connect to the default Users container of the domain.

Check out the Sysinternal AD Explorer - an invaluable tool to take a peek inside your AD and to understand the various bits and pieces in there (and how they are addressed by LDAP URLs).

Upvotes: 1

Related Questions