cannot add user into Active Directory via c#.net

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 as this picture link
below:.

http://img21.imageshack.us/img21/2654/errorweb3.jpg

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

               }
           
           
       }
   }

I search in google about adding user into Active Directory.The most results
are like my code and can run well while I cannot. Why?

-- 
Message posted via http://www.dotnetmonster.com

0
dexterMor
3/5/2010 3:00:13 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

1 Replies
948 Views

Similar Articles

[PageSpeed] 1

"dexterMor" <u53265@uwe> wrote in message news:a48a26c744cbe@uwe...

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

> I search in google about adding user into Active Directory.The most 
> results
> are like my code and can run well while I cannot. Why?

The error message is telling you that one of the properties you're trying to 
assign to the user object does not exist. Rem them all out apart from the 
first one and then add them back in one at a time until you find the one 
which is incorrect. It's been a while since I did any AD stuff, but 
["AccountName"] doesn't look right to me - are you sure it's not 
sAMAccountName? Not sure about ["Address"] either...
http://www.kouti.com/tables/userattributes.htm

Don't forget that C# is case-sensitive...


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net 

0
Mark
3/5/2010 3:46:23 PM
Reply:

Similar Artilces:

Prevent User to grant mailbox access permission
Hi, there, By default, in Outlook user can grant other user access permission to his/her mailbox folder. But, our company doesn't want this. Is there anyway to prevent user to grant access permission to his/her own mailbox and sub- folders? Any input is much appreciated. David ...

How to add another user's Contacts folder to my Address Book?
Background: Exchange 2003 Server w/ Outlook 2000/2003 clients. I can add any Contacts folders in my mailbox to my Address Book by going into the Properties of the folder and checking "Show this folder as an e-mail Address Book" on the "Outlook Address Book" tab. However, if I have another user's mailbox (to which I have full permission) in my Folder List, I do not have this option in any of their Contacts folders. How do I add another user's Contacts folder, displayed in my Folder List, to my Address Book? TIA, roshan After a bit of research on SlipStick.com...

Is it possible to log the user's IP address or computer name?
We have Exchange 5.5 here and some users know other's email password. Is there anyway to log the machine IP address since under the property store you can only see the last logon with the user. Can't tell anything if multiple users sign on simultaneously? Lisa ...

Creating a Relationship Between Order Product (salesorderdetail) and Service Activity (serviceappointment)
Hi folks, We are using CRM 4.0 to run a consulting business. Its working pretty well but we want to simply the way we are doing some things. What we want to do is create an Order (salesorder) with multiple Order Products (salesorderdetal). So good so far. Next I want to be able associate each Order Product (salesorderdetail) with a Service Activity (serviceappointment), this representing that this billable line item in the order is actually going to be fulfilled as a consuting engagement. The problem is, I can't seem to be able to create an association between the Order Product (salesor...

CRM3.0 Question on Activity
Hello, I am using CRM3.0. I have the following case. 1. Create Campaign 2. Add contact to campaign list 3. Create Campaign activity - Phone call 4. Distribute activity 5. CRM User will make phone call 6. When contact is interest, CRM user will make a "Free Trail" for contact. I am having troble in step 6. So far as I know, I have two choices for "Free Trail". A) Service Activity If I choose to create a service activity, then I can not link up the service activity with the campaign or phone call. B) Appointment If I choose appointment, I can set "regarding"...

deleting CRM users??
Is there a way to delete the users from the users folder? It doesn't seem like you can get rid of them or change the groups that they belong to if you make a mistake, etc. You can't delete CRM users, you just have to disable them. "wlandymore" wrote: > Is there a way to delete the users from the users folder? It doesn't seem > like you can get rid of them or change the groups that they belong to if you > make a mistake, etc. Hi, It is possible to hard delete a users in the ms crm database, but of course this is not supported. If you chose to delete this...

Refreshing a User Defined Function
To all: On Sheet 1 of my workbook, I have a date in cell A1. In the next sheet, I want the same date as the previous sheet plus seven days. When I copy the latest sheet, I want it to reference the sheet located prior to it rather than referencing the original sheet (Sheet 1). After copying 52 worksheets, I want each of them to reference the sheet located just prior to each of the sheets. I found this User Defined Function posted here on this discussion site and it works great except for one thing. If I change the original date on Sheet 1, the UDF does not automatically update. Is...

pass parameters back from C/C++ to JScript
Hi, all I import Microsoft Webbrowser Control to my VC6 MFC project and customize the web browser with my own doc handler. The following is the implemenation: ICustomDoc * pCustdoc; m_WebBrowser.GetDocument()->QueryInterface(&pCustdoc); // m_WebBrowser is an instance of Microsoft Webbrowser Control if (pCustdoc) { pCustdoc->SetUIHandler(m_pDocHandler); // m_pDocHandler is my doc handler for the web browser. pCustdoc->Release(); } Then I can call C/C++ functions from web page JScript, such as: external.MyFunc("abcdef"). In this way, I can pass parameters fr...

Office 2004 Project Gallery
> This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3184399017_17854679 Content-type: text/plain; charset="ISO-8859-1" Content-transfer-encoding: 8bit In the main screen of the Office 2004 Project Gallery, there are icons for things like �Mail Message� and �Calendar Event�. How can I add, for example, �Address Book Entry� or �Task� to the Project Gallery? --B_3184399017_17854679 Content-type: text/html; charset="ISO-8859-1" Content-transfer-encoding: quoted-printable <HTML...

Add a new code macro
I have workbook that I am trying to use with a macro form another post on this form. It inserts a new row with the formulas and contents of the selected row. The problem is that it copies the row below the one selected, and because of this, I can not make a copy of row 2 below the column headers. Any ideas? Thanks. Here is the code: '/=======Start of Code==========================/ Sub InsertRowsAndFillFormulas() 'adds desired # of lines below the current line and ' copies the formulas to that/those lines 'added selection of more than one worksheet ' - Gary L. Brown &#...

I can add an extra calendar, but can't share it??
At my workplace we have a dozen of calendars for the rooms we use, like: - Meeting room1 - Meeting room2 - Jobcar1 - Jobcar2 and so on. Now we have calendar-books for each of them, and every time I want to reserve a room or the car I have to walk at least 50 meters... I thought it would have been nice if we could use Outlook calendar for this, I have now added a calendar, but it's not possible for anybody else to open it..? why? Are there better ways of doing this? (I know there are web-calendars and so on, but outlook would be much more convenient).. Best regards, =D8ystein In ne...

Logged in as wrong user
I did try posting onto a previous question on this topic but haven't had a reply as it is way down the list of postings so perhaps noone has noticed it. I have somehow managed to get myself in a knot - when I try and log onto CRM from my PC as myself I am ending up logged on as CRM Admin. I have obviously checked a box about "remember password" or somesuch but deleting cookies and restarting the PC hasn't helped (although everywhere else is now prompting me to re-enter my login details). All previous references to this explain the problem but don't tell me how to ...

Limited User can't use Money
I've installed Money 2004 in hopes to clear this same problem I had with 2001, to no avail. I installed Money 04 with my System Administrator acct. It works fine for me. But when my wife tries with her Limited Account, she cannot get access. How do I get her access to this program and data? I've tried installing it in the All Users dir, but no help. I really don't want to give her Sys Admin priveleges just to use Money. Thanks to anyone that can help. MS Support has no info on this, nor does a Google search turn anything up. If she creates a new Money file, can you b...

copy and match data from one worksheet into another via script?
Hi all I have two worksheets 2 columns each The first sheet has ID and Name Column for example: Code ------------------- ID[/B] NAM 193948 Michael 684588 John 535279 Luke 098734 Matthe ------------------- my 2nd sheet Code ------------------- ID [B]NAM Michael John Luke Matthe ------------------- How do i use the first sheet to match up the names on the 2nd sheet and ultimately copy the ID numbers onto the 2nd sheet? This is just a simplified example. There are thousands of entries. Thank you if you have ...

How to detect when user switches between open forms?
The user can have multiple non-modal, restored, forms open at once and can switch between them as they want, often by just clicking on their titlebars. These forms are all instances of F_URL. I am using Vista, Access 2007. How do I run a routine anytime the user switches form? F_URL.GotFocus doesn't fire because the Focus event only fires for the particular control that has the focus on the form, and, there are many such possible controls. F_URL.Activate doesn't fire. So, four possibilities as far as I can see: 1. There is probably some obvious event that I'm ju...

ServerXMLHTTP in .NET ?
Hi, is there something like the ServerXMLHTTP object from MSXML available in .NET ? I searched in the VS help, but just found documentation for the MSXML object.... Greetings, Raik See docs for: System.Net.HttpWebRequest System.Net.HttpWebResponse -- Teemu Keiski MCP, Designer/Developer Mansoft tietotekniikka Oy http://www.mansoft.fi ASP.NET Forums Moderator, www.asp.net AspAlliance Columnist, www.aspalliance.com Email: joteke@aspalliance.com "Raik Hoffmann" <raik.hoffmann@invensys.com> wrote in message news:098701c33fb9$998d4da0$a301280a@phx.gbl... > Hi, > ...

COM communicate with managed code(.NET)
Hi! When I have a communication from COM to managed code(.NET) a type library(TLB) is necessary in between to handle the communication from COM to ..NET. I tried to use Red Gats's reflector to look into the type library that have extension tlb but it's not possible. So why is it not possible ? //Tony "Tony Johansson" <johansson.andersson@telia.com> wrote in message news:O%23lutgv5KHA.5464@TK2MSFTNGP05.phx.gbl... > I tried to use Red Gats's reflector to look into the type library that > have extension tlb but it's not possible. ...

HTML report in vb.net
How do I create an html report in vb.net instead of Crystal or ReportViewer? Hello, > How do I create an html report in vb.net instead of Crystal or > ReportViewer? Pretty vague. If the problem is to create html markup you could try the HtmlTextWriter class (http://msdn.microsoft.com/en-us/library/system.web.ui.htmltextwriter(VS.80).aspx to see if it's easier for you. Also most Reporting Packages (including RS, note sure about Crystal but very likely) are able to render a report as HTML markup so you could perhaps still use them. Not sure what is your scena...

Sharing folders between User Accounts on same PC
Non of my data is stored on C: but on another partition on the drive. I have several User Accounts for different hobbies, etc. I want to share a folder so it is viweable on the desktops of the User Accounts, but I don't want to move the folder onto C: - I want it to stay in it's location. Is this possible? TIA. "Richard" <noggod@ntlworld.com> wrote in message news:eadR9R0HLHA.1868@TK2MSFTNGP05.phx.gbl... > Non of my data is stored on C: but on another partition on the drive. > > I have several User Accounts for different hobbies, etc. &...

Inventory User Categories
hey guys I was wondering of anyone knows how to get the description for Inventory user categories to appear on a report or which table the actual description is held on. I know how to use the user categories from the item master table - but i want to use the description that is entered against this category in item category setup. thanks Theo, I just tred adding it and am sorry to say that it seems difficult in RW. At the very least, you would need to use vba to read the Item Category setup table - IV40600. You could use retrieveGlobals and ADO to read the table and return the value to t...

Replication, when activated
Just moved the database & MS-CRM application to a new server, just as pointed out in the Implementation guide. Everything works fine at this time, exept for the replication. In the SQL-server I cannot see any subscribers or publication articles on the new server. When is replication activated on a CRM server and what should my next step be? I'm thinking to re-install all clients, but I'm not sure this will solve the problem. Second question is what is the 'configure SQL' option is doing exactly ? At this time my deployment consists of 2 CRM servers (old and new), and...

Error 1004 Workbooks.Add Inplace-Activation
Hi ! I don't know if I am in the correct forum but here it comes any way Sub AddWorkBook() ThisWorkbook.Application.Workbooks.Add End Sub this simple macro only works from the debugger environment if I have XL Inplace Activated Is there any workarounds ? Best regards Magnus Is it so that XL has a state that it cannot do this ? COleClientItem::activeUIState Do I have to change state to pItem->DoVerb (OLEIVERB_OPEN, pView ); ???? "Magnus Pettersson" <magnus@businessvision.se> wrote in message news:uRngzLSvEHA.536@TK2MSFTNGP11.phx.gbl... > Hi ! > I d...

everything wants to connect to net
I've been happily running Outlook 2002 for a year or more. Recently uploaded activsynd and reinstalled Outlook 2002 with my new pda (ipaq h2210). Now everything seems to want to connect to the net and it didn't before. I don't have broadband so, this is irritating. Can I stop that happening? Martin ...

Simple MFC/C++ development question
I want to develop a simple GUI utiliy using C++/MFC. I mostly develop for Linux using Java/C and I am used to used Sun's JDK and GNU's C compiler running under Linux. My question is where can I get a minimum set tools I need to develop a MFC application. I don't really want an IDE (i.e. VC++6) - what I'm after is a compiler and the header/libraries to link my MFC based utility against. I will use my favourite editor to enter the code. TIA Paul. anonymous@discussions.microsoft.com wrote: > I want to develop a simple GUI utiliy using C++/MFC. > > I mostly d...

Distro List Managed by Users
I would like to create a list that 2 or 3 users have rights to add to and remove names from. The email distro list is comprised of all email addresses of customers that want daily updates from us. I would like this list to either show up in Contacts or the GAL. I am not sure how to do this in Exchange 2003 and I dont even know what kind of info i should be searching for to find this out. THanks. Autodl "Ken Cheney" <digexrules@yahoo.com> wrote in message news:eEtxVmBLGHA.3352@TK2MSFTNGP12.phx.gbl... >I would like to create a list that 2 or 3 users have rights t...