Answered by:
Allow Users to create sub users

Question
-
User-642154842 posted
Hi All,
I have a website where users can create their own account, so far everything is ok but now i need the users to be able to create New Users under they're account with the same access rights as main user.
Is this possible with asp.net membership provider?
Thanks
Monday, April 28, 2014 9:46 AM
Answers
-
User1140095199 posted
Hi,
Greetings!
Dim cfg As System.Configuration.Configuration = _ WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath) machineKey = CType(cfg.GetSection("system.web/machineKey"), MachineKeySection) If machineKey.ValidationKey.Contains("AutoGenerate") Then _ If PasswordFormat <> MembershipPasswordFormat.Clear Then _ Throw New ProviderException("Hashed or Encrypted passwords " & _ "are not supported with auto-generated keys.")
The above ERROR might be occuring because you haven't set set specific keys in your web.config. You need to specify the Encryption/ Decription Keys:
<machineKey validationKey="your value" decryptionKey="your value" validation="AES" decryption="Auto" />
Refer to the following article - http://msdn.microsoft.com/en-us/library/ms998288.aspx
Also refer to the following POSTs (Similiar Issues) :
http://community.codesmithtools.com/nettiers/f/16/t/12930.aspx
Hope it helps!
Best Regards!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 30, 2014 3:02 AM
All replies
-
User-425639139 posted
You can customize the Membership and add aditional fields, have a check box or dropdown allow user to select if they want a sub accout:
http://msdn.microsoft.com/en-us/library/vstudio/ms366730(v=vs.100).aspx
Monday, April 28, 2014 9:56 AM -
User465171450 posted
Yes and no. There is absolutely no feature in ASP.Net for this, but that doesn't necessarily prevent you from adding your own functionality to work with the membership providers. You would need another table that would hold a one-to-many relationship between the parent user, and the child user.
You may also need to roll your own membership provider (which isn't hard actually) to handle scenarios such as: what happens when the parent user's roles are changed, is that copied automatically to all child user's as well?
It wouldn't be too hard to write your own functions that wrap up the steps needed. Something like an AddUser function that would take in enough information to use the standard Membership.CreateUser, as well as the parent account's id so you can call your own function that stores the parent id, with that returned by CreateUser into that one-to-many table I described earlier.
Monday, April 28, 2014 9:59 AM -
User-642154842 posted
Thanks i'll give it a go....
Monday, April 28, 2014 12:02 PM -
User-642154842 posted
Hi
i tryed the sugestion above but got "Hashed or Encrypted passwords are not supported with auto-generated keys."
Dim cfg As System.Configuration.Configuration = _ WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath) machineKey = CType(cfg.GetSection("system.web/machineKey"), MachineKeySection) If machineKey.ValidationKey.Contains("AutoGenerate") Then _ If PasswordFormat <> MembershipPasswordFormat.Clear Then _ Throw New ProviderException("Hashed or Encrypted passwords " & _ "are not supported with auto-generated keys.")
Thanks
Tuesday, April 29, 2014 8:14 AM -
User1140095199 posted
Hi,
Greetings!
Dim cfg As System.Configuration.Configuration = _ WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath) machineKey = CType(cfg.GetSection("system.web/machineKey"), MachineKeySection) If machineKey.ValidationKey.Contains("AutoGenerate") Then _ If PasswordFormat <> MembershipPasswordFormat.Clear Then _ Throw New ProviderException("Hashed or Encrypted passwords " & _ "are not supported with auto-generated keys.")
The above ERROR might be occuring because you haven't set set specific keys in your web.config. You need to specify the Encryption/ Decription Keys:
<machineKey validationKey="your value" decryptionKey="your value" validation="AES" decryption="Auto" />
Refer to the following article - http://msdn.microsoft.com/en-us/library/ms998288.aspx
Also refer to the following POSTs (Similiar Issues) :
http://community.codesmithtools.com/nettiers/f/16/t/12930.aspx
Hope it helps!
Best Regards!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 30, 2014 3:02 AM -
User-642154842 posted
Hi Thanks for your reply,
i did get that sorted but got other issues, the user was created on users table and nowhere else (roles and profiles tables)
i am thinking to take a different approach:
Create User test1, test2, test3 then create roles test1, 2, 3 end when test1 user creates a new user they will be given test1 role.
any suggestions?
Thanks
Wednesday, April 30, 2014 5:13 AM -
User1140095199 posted
Hi,
i am thinking to take a different approach:
Create User test1, test2, test3 then create roles test1, 2, 3 end when test1 user creates a new user they will be given test1 role.
While you create the Users associate the User to the Roles.
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { string userName = CreateUserWizard1.UserName; Roles.AddUserToRole(userName, "Accountants"); }
For more reference:
http://forums.asp.net/t/1259172.aspx?Add+user+to+role+programmatically
http://msdn.microsoft.com/en-us/library/system.web.security.roles.addusertorole(v=vs.110).aspx
Best Regards!
Friday, May 2, 2014 6:05 AM