Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Active Directory Integration using C#.net

Active Directory Integration using C#.net

Scheduled Pinned Locked Moved C#
csharpdatabasedotnetvisual-studiowindows-admin
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shanthivasan
    wrote on last edited by
    #1

    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

    S E 2 Replies Last reply
    0
    • S shanthivasan

      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

      S Offline
      S Offline
      sathish s
      wrote on last edited by
      #2

      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[^]

      S 1 Reply Last reply
      0
      • S sathish s

        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[^]

        S Offline
        S Offline
        shanthivasan
        wrote on last edited by
        #3

        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.

        S 1 Reply Last reply
        0
        • S shanthivasan

          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.

          S Offline
          S Offline
          sathish s
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • S sathish s

            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.

            S Offline
            S Offline
            shanthivasan
            wrote on last edited by
            #5

            thanks a lot sathish. I am through.I did a mistake in DirectorySearcher.

            1 Reply Last reply
            0
            • S shanthivasan

              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

              E Offline
              E Offline
              ekynox
              wrote on last edited by
              #6

              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); }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups