Creating a user to login with using the Login Control and the Ad provider... can't log user in after creation


 

Hi I'm trying to create a user in AD from a web form, and then have the user be able to login to a web form with the login control and the Ad provider.

 

I have a user created by someone else in AD that can log in, but when I create the user using the code below they can't login.

 

Does anyone have any idea what I'm not doing to enable this user correctly, hes in the same ou and the same groups as the user that can login.

the only difference i can see is the display name is not set and the AdminCount has not been set yet... I'm not doing any admin stuff , just logging in... so thouse should not matter, correct?

(Code to create a user below)

Thanks,  

  

public
string CreateUserAccount( string userName, string fName, string lName, string userPassword )

{

string oGUID = "";

try

{

oGUID = string.Empty;

 

DirectoryEntry dirEntry = ROOT2;

//DirectoryEntry Users = dirEntry.Children.Find( "Users" );

DirectoryEntry newUser = dirEntry.Children.Add( "CN=" + userName, "user" );

newUser.Properties[ "samAccountName" ].Value = userName;

newUser.Properties[ "userprincipalname" ].Value = userName + "@AD.JCSN.org";

newUser.Properties[ "givenname" ].Value = fName;

newUser.Properties[ "sn" ].Value = lName;

newUser.Properties[ "displayname" ].Value = fName + " " + lName;

newUser.Properties[ "admincount" ].Value = 1;

dirEntry.Properties[ "member" ].Add( "CN=Domain Admins" );

newUser.CommitChanges();

oGUID = newUser.Guid.ToString();

newUser.Invoke( "SetPassword", new object[] { userPassword } );

newUser.CommitChanges();

dirEntry.Close();

newUser.Close();

try

{

AddToGroup2( newUser.Properties[ "distinguishedName" ].Value.ToString(), "CN=Domain Admins" );

}

catch ( Exception ex )

{

throw;

}

 

}

catch ( System.DirectoryServices.DirectoryServicesCOMException E )

{

//DoSomethingwith --> E.Message.ToString();

}

return oGUID;

}

public void AddToGroup2( string userDN, string groupDN )

{

// Bind to the group.

DirectoryEntry group = ROOT2.Children.Find( groupDN );

//DirectoryEntry user = ROOT2.Children.Find( userDN );

// Add the user to the group.

group.Properties[ "member" ].Add( userDN );

// Commit the changes to the group.

group.CommitChanges();

}

0
caladin
4/16/2008 5:43:55 PM
asp.net.security 27051 articles. 1 followers. Follow

0 Replies
1353 Views

Similar Articles

[PageSpeed] 19
Get it on Google Play
Get it on Apple App Store

Reply:

Similar Artilces:

I can create new user (auto-logged-in) but I can't log in using login-control???
Hi there,  I am a little at loss here. I can create new user and I can set in code that I should be logged in after creation - but if I logout, I can never log in again. I've tried creating new users to be sure I didn't make a mistake with the password, but I simply can't log in! The user is created in database and the page visit is logged in my log table (so I can update the database) I've tried Dim r As Boolean = FormsAuthentication.Authenticate("ajuaju", "xxxxxxx.") which returns false even for the correct password. Is the authentication p...

Cannot open user default database. Login failed. Login failed for user 'DOMAIN\User'. (.Net SqlClient Data Provider)
Hi when i try and open a database in sql server management studio i get the error "Cannot open user default database. Login failed. Login failed for user 'DOMAIN\User'. (.Net SqlClient Data Provider)", what can i do to rectify this, i have googled around and still havent found no answers. Which authentication mode is your Sql Server configured - MixedMode, Windows Authentication or Sql Server Authentication? Please refer to http://msdn2.microsoft.com/en-us/library/ms366351.aspx and http://blogs.msdn.com/sql_protocols/archive/2006/02/21/536201.aspx    Ple...

can't login with a userid created progammatically, using a Login control..
I have the following code behind code and web.config file entry along with the additional sql (to store additional info in a separate table) to create a new user, but can't login using the user name created using a login control. Tried membership.ValidateUser, it returns false for user created through the code behind. Although i can login using userid created through ASP.NET Config tool - code behind - Dim User As MembershipUser Dim Status As MembershipCreateStatus TryUser = Membership.CreateUser(txtUserId.Text.ToString(), txtPassword.ToString(), txtEmail.Text.ToString(), N...

Login and CreateUserWizard component, users created yesterday can't login today
Hi,I'm pretty new to ASP.NET, SQL and VWD 2008 Express but have hit upon a problem with site users and getting them to login. After much searching on google and trawling through the forum I have yet to find an answer that works so here is my first post.The Problem:I have used the website administration tool to set up my main user and permissions etc, so a database is created which holds all the userdata in "aspnet_" tables. Once I had done this I made a form and used the CreateUserWizard component which worked fine when I ran it and added users to the tables created by the web ...

login script provided--User cannnot login as local user the script fails but can login as local admin on xp pc
> Hi all > the error is as follows > novell client scripts has encountered a problem > and needs to close > the exception unknow s/w exception 0xc06d007e > occured in the application at location ox77e738b2 > I have never seen this before and i have tried reinstalling the cleint > but it didnt work. This occurs when the user ins logged into a xp pro pc > as a user though it doesnt occur when logged in as a local admin on the > box. this is only happening on one box. > Login script is below > MAP ERROR OFF BREAK OFF if member of ".every...

I can create users, but they can't login
This is my first attempt at creating and using login controls.  I'm using everything 'right-out-of-the=box' just to get a feel for it, and to get something working before I start playing around with it.I'm using SQL Server 2005, not express, so I have this in my web.config:<connectionStrings>        <remove name="LocalSqlServer"/>        <add name="LocalSqlServer" connectionString="Data Source=IPString,port;Initial Catalog='mainshiptest';Integrated Security=False;User ID=******;Password=******;" providerName="Sys...

users can't login from mac
I recently re-did our Novell 5.1 server and changed it to NW6.5 and NW6.0 I started with a fresh new install, new tree, etc. I have one NW6.5 and one NW6 on the tree. I have installed simple passwords. Now when the teachers came back to school to prepare for classes, I had my first surprise. Some of the teachers cannot login from a Mac (OS9 - have not tested the OS X), but they can login from a PC. On the other hand some of the school adminstrators, myself as sysadmin and one of the teacher accounts CAN login from the Macs I am baffled by this. Where can I look to troubleshoo...

Login Control logs user in, but User is not authenticated, but user really is!
I am using aspnetmembershipprovider.  Everything works fine.  I slap a login control on my login page and am able to login and get to my secure folder etc.  When I try and put some code in the LoggedIn method "User.Identity.IsAuthenticated" = false, yet if I blow through that, I am logged, authenicated etc.  The documentation says that the LoggedIn event is "after the user is authenticated".  Any Ideas what is up?Thanks,TPS------------------------------------------------------Note Collaboration for your next confernce call.http://www.ConferenceCallNotes.com I am...

Login failed for user 'Bachelorplace'. The user is not associated with a trusted SQL Server connection. (.Net SqlClient Data Provider)
please tellme how to resolve this error, i m using server studio management tool. and trying to connect using sql server authentication. my pc is over a domain.   Login failed for user 'Bachelorplace'. The user is not associated with a trusted SQL Server connection. (.Net SqlClient Data Provider)  check whether that sql server is allowing sqlauthentication or not.select that server -> right click it-> select  properties  -> in the window, select security -> check what is the server authentication. it should be  sqlserver and windows authentica...

I use an CreateUserWizard control to create new user account. Every time I create a new account, my logined account will change to the new one. How can i keep my current account after creating the new
I use an CreateUserWizard control to create new user account. Every time I create a new account, my logined account will change to the new one. How can i keep my current account after creating the new account? Simply set the "LoginCreatedUser" property of CreateUserWizard control to FALSE!  ...

login control can i used to controll what data can user see it
i have a project with mulit company can i used login control to control what company user can see it and what user cant see it the company comes from databasethanks alot for any helphttp://www.feckra.com/blog/ first of all you should have a table in database database that contains (user_id, company_id,  password, auth_level). the auth_level can be used to grant specific content/page access to each user of each company. but, you need to override the authentication process as bellow.    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { L...

Cannot open database "DataBase" requested by the login. The login failed.Login failed for user 'User\ASPNET'.
hi all, i am having my asp.net project and database is in same system. in web.config i diclaire my connection string as <add name="MyWebConString" connectionString="Data Source=AIPL069\SQLEXPRESS;Initial Catalog=MyWeb;Integrated Security=True" providerName="System.Data.SqlClient"/> when i login application i got an error error is Server Error in '/MyWeb' Application. Cannot open database "MyWeb" requested by the login. The login failed.Login failed for user 'AIPL069\ASPNET'. Description: An unhandled exception...

Will the login control update User's lastactivitydate when logging user in?
After a user logged in, I want to check his lastactivitydate. But I don't know whether the login control I use will update user's lastactivitydate automatically when athenticating user.If the log in control does, that means I always get DateTime.Now if I retrieve user's lastactivitydate just after his log in.I searched MSDN, it doesn't seems there is an answer yet. Welcome to My Blog:.Net Framework Student I guess so, but before login you have the username. Thus you can retrieve user information before the user thechnically logs in.Please remember to 'Mark as Answe...

if a user is in his session ,another user can't login with that username and password
 in my site i used session for log in of users.when user is in his session ,and another user have his username and password to log in from another computer ,how can i show a message?(becuase a user is in his session and another user wantts to log in with the username  and password of that user.) hi, check this url, http://www.eggheadcafe.com/articles/20030418.asphttp://www.eggheadcafe.com/articles/20030416.asphttp://forums.asp.net/t/1233680.aspx  I  used a field in my database that ,when user login value of it be true,.and when logout it will be false(writhin code i...

Web resources about - Creating a user to login with using the Login Control and the Ad provider... can't log user in after creation - asp.net.security

Resources last updated: 1/18/2016 10:52:49 AM