locked
!!!!!Urgent Cannot add user account in Active Directory via ASP.net RRS feed

  • Question

  • User-961927681 posted

    My System Have 2 Computer:

    Frist Computer act as A domain Controller that has a Active Directory,RADIUS Server,DHCP and DNS

    Second Computer act as A Web Server(join domain with a first computer already) and use Microsoft Visual Studio Team System 2008


    I create a website on a second computer to add user in active directory. I have 3 file:
    1.Default.aspx - Let user fill their privacy information

    2.ViewRegisterdata.aspx - Let user confirm their information before it's added to active directory. In this file,there is a Viewregisterdata.aspx.cs which collect user information and send to Class1.cs when users click confirm button.

    3.Class1.cs - Do the process in adding user in active directory



    I have a problem with a third files.
    When I run the website and go to a second page that is a ViewRegisterdata.aspx and then press a confirm button,it shows an error.

    This is my code in a third file:

    using System;
    using System.Collections;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.DirectoryServices;



    namespace senior
    {
        public class Class1
        {
            public struct UserInfo
            {
                public string username;
                public string AccountName;        
                public string firstname;
                public string lastname;
                public string address;
                public string email;
                public string displayname;
                public string password;
                public string givenName;
            }
           
                UserInfo newUserInfo;
                public Class1(string Rfirstname, string Rlastname, string Raddress, string Remail, string Rdisplayname,
                    string Rusername, string RaccountName)
                {
                    newUserInfo.firstname = Rfirstname;
                    newUserInfo.lastname = Rlastname;
                    newUserInfo.address = Raddress;
                    newUserInfo.email = Remail;
                    newUserInfo.displayname = Rdisplayname;
                    newUserInfo.username = Rusername;
                    newUserInfo.AccountName = RaccountName;


                    DirectoryEntry adUserFolder = new DirectoryEntry("LDAP://10.1.0.1/CN=Users;DC=seniorproject,DC=COM","Administrator@seniorproject.com","********");

                    if (adUserFolder.SchemaEntry.Name == "container")
                    {
                        
                            DirectoryEntry newUser = adUserFolder.Children.Add("CN=" + newUserInfo.username, "User");
                            
                            if (DirectoryEntry.Exists(newUser.Path))
                            {
                                Console.Write("The user:" + newUser.Username + "exists, they will be deleted");
                                adUserFolder.Children.Remove(new DirectoryEntry(newUser.Path));
                            }
                            newUser.Properties["AccountName"].Value = newUserInfo.AccountName;
                            newUser.Properties["givenName"].Value = newUserInfo.firstname;
                            newUser.Properties["sn"].Value = newUserInfo.lastname;
                            newUser.Properties["displayName"].Value = newUserInfo.displayname;
                            newUser.Properties["Address"].Value = newUserInfo.address;
                            newUser.Properties["email"].Value = newUserInfo.email;
                            //newUser.Properties["Password"].Value = "Y7l11909";

                            newUser.CommitChanges();

                            newUser.Invoke("setPassword:", "P@ssword:");
                            newUser.Properties["userAccountControl"].Value = 0x0200;
                            newUser.CommitChanges();
                        }

                    }
                
                
            }
        }


    Tuesday, March 2, 2010 12:35 AM

All replies

  • User-1659704165 posted

    Hi,

    1. Check the IIS application pool account of the 2 servers: working/non-working : s/be the same Are these load balancing servers  for the web apps ?

    2. Make sure the IIS application pool acct/ASP.NET has read access to the file system where the apps is on.

    OR

    http://forums.asp.net/p/1316827/2607261.aspx#2607261

    http://www.petri.co.il/forums/showthread.php?t=29789

    http://www.eggheadcafe.com/software/aspnet/31578130/hithis-is-permissions-is.aspx

    have seen the abvoe link

    Tuesday, March 2, 2010 12:53 AM
  • User-961927681 posted

    Hi,

    1. Check the IIS application pool account of the 2 servers: working/non-working : s/be the same Are these load balancing servers  for the web apps ?

    2. Make sure the IIS application pool acct/ASP.NET has read access to the file system where the apps is on.

    OR

    http://forums.asp.net/p/1316827/2607261.aspx#2607261

    http://www.petri.co.il/forums/showthread.php?t=29789

    http://www.eggheadcafe.com/software/aspnet/31578130/hithis-is-permissions-is.aspx

    have seen the abvoe link

    I didn't see the accounts as you tell. This my application pool:



    Tuesday, March 2, 2010 1:55 AM
  • User-1659704165 posted

    How Modfiy the user IIS Rights

    http://coppermine-gallery.net/tutorial/permissions/iis.php

    Modify as per your requirmenet.

    Tuesday, March 2, 2010 1:57 AM
  • User-961927681 posted

    I do that first before occur this problem

    Tuesday, March 2, 2010 2:24 AM
  • User-1659704165 posted


    http://www.java2s.com/Code/CSharp/Web-Services/DirectoryEntryGetProperties.htm

    Remove Console.WriteLine and replace it with the Responsewrite and Cros verify the proptery u atrying to Aces

    Tuesday, March 2, 2010 2:30 AM
  • User-961927681 posted

    I understand your sentence before "and" but a sentence after it, I don't get it.


    Tuesday, March 2, 2010 2:40 AM
  • User-1659704165 posted

    Cross  verify the proptery u are trying to Acess.. AccountName,givenName etc ..

    as error describes "Specified directory service attribute or value does not exist"


    Tuesday, March 2, 2010 2:45 AM
  • User-1659704165 posted

    have seen the link

    http://learn.iis.net/page.aspx/624/application-pool-identities/

    Tuesday, March 2, 2010 3:03 AM
  • User-961927681 posted

    Cross  verify the proptery u are trying to Acess.. AccountName,givenName etc ..

    as error describes "Specified directory service attribute or value does not exist"


    Thanks. I solve my problem

    I change a postion that is a problem:

    From newUser.CommitChanges(); to adUserFolder.CommitChanges();

    the "newUser" variable is assigned with this value "adUserFolder.Children.Add("CN=" + newUserInfo.username, "User")"


    When I changed and run a website again via Visual Studio I got this error instead


    Tuesday, March 2, 2010 3:31 AM
  • User-961927681 posted

    have seen the link

    http://learn.iis.net/page.aspx/624/application-pool-identities/

    I use Windows Server 2003 not 2008

    Tuesday, March 2, 2010 3:33 AM
  • User-1659704165 posted



    http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/09998c61-7d18-4798-b063-37922209a8be

    http://directoryprogramming.net/forums/thread/1738.aspx

    chk the above link

    Tuesday, March 2, 2010 4:07 AM
  • User-961927681 posted

    Thanks.but I look at Active directory in the first computer. There is not a user account that I create via a Website.


    Wednesday, March 3, 2010 1:59 AM