Google Answers Logo
View Question
 
Q: Add new user / delete user / set group in VB.Net web application ( No Answer,   4 Comments )
Question  
Subject: Add new user / delete user / set group in VB.Net web application
Category: Computers > Programming
Asked by: mindwalker-ga
List Price: $25.00
Posted: 06 Jan 2006 08:12 PST
Expires: 09 Jan 2006 10:22 PST
Question ID: 429947
I need to add a new user account, set the user's group, and delete
the user account from within a VB.Net web application. All the examples
I've tried so far have not worked. I am using code like this to try to
add a user:

Dim objDomain as Object
objDomain = GetObject("WinNT://" & _strDomainName)

objUser = objDomain.Create("user", _strUsername)
objUser.SetPassword(_strPassword)
objUser.FullName = _strLastName & ", " & _strFirstName
objUser.Description = _strDescription
objUser.SetInfo()

the SetInfo() generates an exception like this:

at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack, Boolean IgnoreReturn) at
Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall(Object o,
Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack) at AddUser(String _strUsername, String
_strPassword, String _strLastName, String _strFirstName, String
_stGroup)

Note that the code *does* work for a Windows app, but I need it to
work for a web app. It could simply be a permissions issue.

The correct answer to this question will have all of the following:

1. Be written in VB.Net
2. Require no changes to the web.config file
3. Include the simplest working examples for adding a user, setting a
user's group, and deleting a user.
4. It must work for me.

Clarification of Question by mindwalker-ga on 09 Jan 2006 10:22 PST
None of the suggestions so far have worked, however, I'm happy to
report that I did figure out a way to get it working. I just needed to
turn on identity impersonation for the page that creates/deletes
users. That was necessary because we are using basic authentacation
and the logged in user will have the necessary privileges if using
impersonation.

To turn on identity impersonation, I place code similar to the
following in the web.config file:

<location path="path.aspx">
<system.web>
<identity impersonate="true" />
</system.web>
</location>  

I'll close out this question.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Add new user / delete user / set group in VB.Net web application
From: pmmbala1976-ga on 07 Jan 2006 08:26 PST
 
Not sure this link will help you completely. May be you can get some
details from them.

http://www.15seconds.com/issue/011127.htm
http://forums.asp.net/316534/ShowPost.aspx

thanks
bala
Subject: Re: Add new user / delete user / set group in VB.Net web application
From: caiius-ga on 07 Jan 2006 13:47 PST
 
Try to put ASP.NET user in Administrators Group ;)
Subject: Re: Add new user / delete user / set group in VB.Net web application
From: kindageeky-ga on 07 Jan 2006 21:48 PST
 
The problem may be the credentials of the thread running in the web
application may not have privileges to modify data in Active
Directory.  You might try changing the security principle of the
thread prior to connecting to AD, possibly as follows ...

Dim principal as WindowsPrincipal 
Dim identity as WindowsIdentity identity
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
principal = DirectCast(Thread.CurrentPrincipal, WindowsPrincipal)
WindowsIdentity identity = DirectCast(principal.Identity, WindowsIdentity)
System.Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")

Hope this helps,
Kindageeky
Subject: Re: Add new user / delete user / set group in VB.Net web application
From: mindwalker-ga on 09 Jan 2006 10:22 PST
 
None of the suggestions so far have worked, however, I'm happy to
report that I did figure out a way to get it working. I just needed to
turn on identity impersonation for the page that creates/deletes
users. That was necessary because we are using basic authentacation
and the logged in user will have the necessary privileges if using
impersonation.

To turn on identity impersonation, I place code similar to the
following in the web.config file:

<location path="path.aspx">
<system.web>
<identity impersonate="true" />
</system.web>
</location>  

I'll close out this question.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy