Active Directory Integration using C#.net
-
I am using VS 2003 .Net framework. I have to integrate the web application with active diretory. I browsed net i found the below code.no luck there. i dont know how to solve the error. void Page_Load(Object Src, EventArgs E ) { if(!Page.IsPostBack) { lblMessage.Text = "use domain\\username format"; } } private void AuthenticateUser(object sender, EventArgs e) { string ldapPath = "LDAP://dc=domain",DC=dn; DirectoryEntry de = new DirectoryEntry(ldapPath); de.Username = txtUsername.Text; de.Password = txtPassword.Text; de.AuthenticationType = AuthenticationTypes.Secure; try { string name = de.Name; //force a bind lblMessage.Text = "Success, You have authenticated"; } catch(Exception ex) { lblMessage.Text = "Failure: " + ex.Message; } finally { de.Close(); } }
User name
password
User name: <%=User.Identity.Name %>
My process is running as: <%=System.Security.Principal.WindowsIdentity.GetCurrent().Name %>I am getting the following exception: Failure: System.Runtime.InteropServices.COMException (0x8007054B): The specified domain either does not exist or could not be contacted at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_Name() at ASP.index_aspx.AuthenticateUser(Object sender, EventArgs e) please advice on this
-
I am using VS 2003 .Net framework. I have to integrate the web application with active diretory. I browsed net i found the below code.no luck there. i dont know how to solve the error. void Page_Load(Object Src, EventArgs E ) { if(!Page.IsPostBack) { lblMessage.Text = "use domain\\username format"; } } private void AuthenticateUser(object sender, EventArgs e) { string ldapPath = "LDAP://dc=domain",DC=dn; DirectoryEntry de = new DirectoryEntry(ldapPath); de.Username = txtUsername.Text; de.Password = txtPassword.Text; de.AuthenticationType = AuthenticationTypes.Secure; try { string name = de.Name; //force a bind lblMessage.Text = "Success, You have authenticated"; } catch(Exception ex) { lblMessage.Text = "Failure: " + ex.Message; } finally { de.Close(); } }
User name
password
User name: <%=User.Identity.Name %>
My process is running as: <%=System.Security.Principal.WindowsIdentity.GetCurrent().Name %>I am getting the following exception: Failure: System.Runtime.InteropServices.COMException (0x8007054B): The specified domain either does not exist or could not be contacted at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_Name() at ASP.index_aspx.AuthenticateUser(Object sender, EventArgs e) please advice on this
-
As is says, Your domain name is wrong. You need to provide valid domain name. To know your domain name you may contact your network administrator. See if the following link is useful for you http://forums.asp.net/p/943717/1340605.aspx[^]
thanks for your reply. I checked the name.It is not working. Do i have to use DirectorySearcher to check the user name? All i have to do is that, i have to get the user name who is currently logging in.
-
thanks for your reply. I checked the name.It is not working. Do i have to use DirectorySearcher to check the user name? All i have to do is that, i have to get the user name who is currently logging in.
-
See if you are authenticating an user by providing a username or against a active directory, then you can get the user name. Its is not possible to get the currently logged in user name from a client system, if he is in someother network.
thanks a lot sathish. I am through.I did a mistake in DirectorySearcher.
-
I am using VS 2003 .Net framework. I have to integrate the web application with active diretory. I browsed net i found the below code.no luck there. i dont know how to solve the error. void Page_Load(Object Src, EventArgs E ) { if(!Page.IsPostBack) { lblMessage.Text = "use domain\\username format"; } } private void AuthenticateUser(object sender, EventArgs e) { string ldapPath = "LDAP://dc=domain",DC=dn; DirectoryEntry de = new DirectoryEntry(ldapPath); de.Username = txtUsername.Text; de.Password = txtPassword.Text; de.AuthenticationType = AuthenticationTypes.Secure; try { string name = de.Name; //force a bind lblMessage.Text = "Success, You have authenticated"; } catch(Exception ex) { lblMessage.Text = "Failure: " + ex.Message; } finally { de.Close(); } }
User name
password
User name: <%=User.Identity.Name %>
My process is running as: <%=System.Security.Principal.WindowsIdentity.GetCurrent().Name %>I am getting the following exception: Failure: System.Runtime.InteropServices.COMException (0x8007054B): The specified domain either does not exist or could not be contacted at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_Name() at ASP.index_aspx.AuthenticateUser(Object sender, EventArgs e) please advice on this
This should work for you. You need to specifiy the domain controller server name including its domain name in full. The following code should make things alot clearer. DirectoryEntry de= new DirectoryEntry(); de.Path = "LDAP://clown.acme.com"; //clown is the server name hosting the domain controller & acme.com is the domain name. de.Username = "administrator"; de.Password = "passw$rd"; de.AuthenticationType = AuthenticationTypes.Secure //now lets search for a user using the above credentials try { DirectorySearcher searcher = new DirectorySearcher(); searcher .SearchRoot = de; searcher .Filter = "(cn=" + "Domin Admins" + ")"; SearchResultCollection results = searcher .FindAll(); Console.Writeline(results.Count.ToString()) } catch (Exception exception) { Console.Writeline(exception.Message); }