I have a web application that was in one Ministry (mof) but is now moving to another Ministry (mop) since the division using the app is moving over to mop.
When the application was in mof, it was correctly connecting to active directory, now that it is goin over to mop I'm trying to configure the LDAP path but it doesn't seem to be connecting. I have used the Softera LDAP Browser and i created a New Profile and it seems to be connected since I am seeing users and folders etc. (not sure if im using this ldap browser correctly but it seems like it is connected)
This is what I had before at MOF and it worked great:
string user = Page.User.Identity.Name.ToString();
user = user.Replace("CORP", "");
DirectoryEntry entry = new DirectoryEntry("LDAP://M05ftd004/DC=corp,DC=M05,DC=gov,DC=local", null,null, AuthenticationTypes.Secure);
entry.Username = @"corp\peter";
entry.Password = "pwd123";
object nativeObject = entry.NativeObject;
if (nativeObject.Equals(true)) MessageBox.Show("connection");// valid entry, user is authenciated
else MessageBox.Show("no connection");
MessageBox.Show(entry.Properties["fullName"].Count.ToString());
However when i try to subs. it for mop configuration (see below) the first message box displays "no connection" and the send count is "0". This is the code for MOP :
string user = Page.User.Identity.Name.ToString();
user = user.Replace("PHE", "");
DirectoryEntry entry = new DirectoryEntry("LDAP://NS1.phe.gov.tt/DC=phe,DC=gov,DC=tt", null, null,AuthenticationTypes.Secure);
entry.Username = @"phe\pan";
entry.Password = "pwdwer";
object nativeObject = entry.NativeObject;
if (nativeObject.Equals(true)) MessageBox.Show("connection");
else MessageBox.Show("no connection");
MessageBox.Show(entry.Properties["fullName"].Count.ToString());
In Softera LDAP Browser I am using the below configurations for creating a new profile:I used the same host name (NS1.phe.gov.tt) port 389, when creating a new profile and the base DN is "DC=phe,DC=gov,DC=tt", for secure credentials under 'prinicpal' i am
using "CN=pan,OU=Maintenance,DC=phe,DC=gov,DC=tt" and it seems to be connected since validation was correct and i am seeing all the users and folders.
Some guidance will greatly be appreciated! Thanks
Ok, apparently my ldap connection was connecting however the problem was when i was searching with the Filter method. Somehow when i get the windows identity and use the replace function a whitespace or some character is added to the user name at the beginning
and the Filter by sAMAccountName was not finding the user. When i place the user name in quotes eg.
mySearcher.Filter ="(sAMAccountName="Peter Pan")";
it would fine! The only resoultion I did and it works not was not to use the replace function and start reading the string from the fourth character. Below is what i did:
string user = Page.User.Identity.Name.ToString();
user = user.Substring(4);
.......
mySearcher.Filter = "(sAMAccountName=" + user + ")";
Instead of
string user = Page.User.Identity.Name.ToString();
user = user.Replace("PHE", "");
Trini_NAtwar...
Member
32 Points
105 Posts
Not connecting to Active Directory through .net
Oct 18, 2011 03:28 PM|LINK
I have a web application that was in one Ministry (mof) but is now moving to another Ministry (mop) since the division using the app is moving over to mop.
When the application was in mof, it was correctly connecting to active directory, now that it is goin over to mop I'm trying to configure the LDAP path but it doesn't seem to be connecting. I have used the Softera LDAP Browser and i created a New Profile and it seems to be connected since I am seeing users and folders etc. (not sure if im using this ldap browser correctly but it seems like it is connected)
This is what I had before at MOF and it worked great:
string user = Page.User.Identity.Name.ToString(); user = user.Replace("CORP", ""); DirectoryEntry entry = new DirectoryEntry("LDAP://M05ftd004/DC=corp,DC=M05,DC=gov,DC=local", null,null, AuthenticationTypes.Secure); entry.Username = @"corp\peter"; entry.Password = "pwd123"; object nativeObject = entry.NativeObject; if (nativeObject.Equals(true)) MessageBox.Show("connection");// valid entry, user is authenciated else MessageBox.Show("no connection"); MessageBox.Show(entry.Properties["fullName"].Count.ToString());However when i try to subs. it for mop configuration (see below) the first message box displays "no connection" and the send count is "0". This is the code for MOP :
string user = Page.User.Identity.Name.ToString(); user = user.Replace("PHE", ""); DirectoryEntry entry = new DirectoryEntry("LDAP://NS1.phe.gov.tt/DC=phe,DC=gov,DC=tt", null, null,AuthenticationTypes.Secure); entry.Username = @"phe\pan"; entry.Password = "pwdwer"; object nativeObject = entry.NativeObject; if (nativeObject.Equals(true)) MessageBox.Show("connection"); else MessageBox.Show("no connection"); MessageBox.Show(entry.Properties["fullName"].Count.ToString());In Softera LDAP Browser I am using the below configurations for creating a new profile:I used the same host name (NS1.phe.gov.tt) port 389, when creating a new profile and the base DN is "DC=phe,DC=gov,DC=tt", for secure credentials under 'prinicpal' i am using "CN=pan,OU=Maintenance,DC=phe,DC=gov,DC=tt" and it seems to be connected since validation was correct and i am seeing all the users and folders.
Some guidance will greatly be appreciated! Thanks
Trini_NAtwar...
Member
32 Points
105 Posts
Re: Not connecting to Active Directory through .net
Oct 21, 2011 03:54 PM|LINK
Ok, apparently my ldap connection was connecting however the problem was when i was searching with the Filter method. Somehow when i get the windows identity and use the replace function a whitespace or some character is added to the user name at the beginning and the Filter by sAMAccountName was not finding the user. When i place the user name in quotes eg.
mySearcher.Filter ="(sAMAccountName="Peter Pan")"; it would fine! The only resoultion I did and it works not was not to use the replace function and start reading the string from the fourth character. Below is what i did:
string user = Page.User.Identity.Name.ToString();
user = user.Substring(4);
.......
mySearcher.Filter = "(sAMAccountName=" + user + ")";
Instead of
string user = Page.User.Identity.Name.ToString(); user = user.Replace("PHE", "");Thanks