473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VB.Net Help : Assign user to role at registration

Hi Guys im still new to all this and im building an app in asp.net 2 vb which will have 4 roles, Admin, Wholesaler, Landscaper, Customer.

When the user sets up there account i want a drop down list box and depending on what role they select (admin wont be included) i want to assign this role to there account. Im using asp.net

Does someone have some code or can you tell me a tutorial or a way of doing this please

Thank you in advance
Apr 20 '07 #1
9 6541
Frinavale
9,735 Expert Mod 8TB
Hi Guys im still new to all this and im building an app in asp.net 2 vb which will have 4 roles, Admin, Wholesaler, Landscaper, Customer.

When the user sets up there account i want a drop down list box and depending on what role they select (admin wont be included) i want to assign this role to there account. Im using asp.net

Does someone have some code or can you tell me a tutorial or a way of doing this please

Thank you in advance
What have you tried already?

-Frinny
Apr 20 '07 #2
radcaesar
759 Expert 512MB
Teddy,
Just try something and if you stuck at some point, then we are glad to help you. What you had asked is not that much difficult.
Apr 20 '07 #3
Hi As per the last message ive now got some code together and it works, im trying to let the user select there account type during registration so i can structure content dependent on the role, the problem i now have is that i have 4 roles, Administrator, Customer, Landscaper, Wholesales, Code below.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3.     Protected Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
  4.         ListBox1.DataSource = Roles.GetAllRoles()
  5.         ListBox1.DataBind()
  6.     End Sub
  7.  
  8.     Protected Sub DeActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
  9.         Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)
  10.     End Sub
  11. </script>
  12.  
  13. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  14.     <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
  15.         <WizardSteps>
  16.             <asp:CreateUserWizardStep runat="server">
  17.             </asp:CreateUserWizardStep>
  18.             <asp:WizardStep runat="server" Title="Choose Account Type" OnActivate="ActivateStep" OnDeactivate="DeActivateStep">
  19.                 Select Account Type:<br />
  20.                 <br />
  21.                 <asp:ListBox ID="ListBox1" runat="server" CssClass="normaltext"></asp:ListBox>
  22.             </asp:WizardStep>
  23.             <asp:CompleteWizardStep runat="server">
  24.             </asp:CompleteWizardStep>
  25.         </WizardSteps>
  26.     </asp:CreateUserWizard>
  27.  
  28.  
  29. </asp:Content>
The problem is i dont want them to be able to add themseleves to the administrator role, but i couldnt work out another way to get the roles and assign them, i found a tutorial that got me this far but now im stuck, your help would be greatly appreciated

Thanks
Apr 21 '07 #4
Teddy,
Just try something and if you stuck at some point, then we are glad to help you. What you had asked is not that much difficult.

Hi As per the last message ive now got some code together and it works, im trying to let the user select there account type during registration so i can structure content dependent on the role, the problem i now have is that i have 4 roles, Administrator, Customer, Landscaper, Wholesales, Code below.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3.     Protected Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
  4.         ListBox1.DataSource = Roles.GetAllRoles()
  5.         ListBox1.DataBind()
  6.     End Sub
  7.  
  8.     Protected Sub DeActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
  9.         Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)
  10.     End Sub
  11. </script>
  12.  
  13. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  14.     <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
  15.         <WizardSteps>
  16.             <asp:CreateUserWizardStep runat="server">
  17.             </asp:CreateUserWizardStep>
  18.             <asp:WizardStep runat="server" Title="Choose Account Type" OnActivate="ActivateStep" OnDeactivate="DeActivateStep">
  19.                 Select Account Type:<br />
  20.                 <br />
  21.                 <asp:ListBox ID="ListBox1" runat="server" CssClass="normaltext"></asp:ListBox>
  22.             </asp:WizardStep>
  23.             <asp:CompleteWizardStep runat="server">
  24.             </asp:CompleteWizardStep>
  25.         </WizardSteps>
  26.     </asp:CreateUserWizard>
  27.  
  28.  
  29. </asp:Content> 

The problem is i dont want them to be able to add themseleves to the administrator role, but i couldnt work out another way to get the roles and assign them, i found a tutorial that got me this far but now im stuck, your help would be greatly appreciated

Thanks
Apr 21 '07 #5
What have you tried already?

-Frinny
Hi As per the last message ive now got some code together and it works, im trying to let the user select there account type during registration so i can structure content dependent on the role, the problem i now have is that i have 4 roles, Administrator, Customer, Landscaper, Wholesales, Code below.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3.     Protected Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
  4.         ListBox1.DataSource = Roles.GetAllRoles()
  5.         ListBox1.DataBind()
  6.     End Sub
  7.  
  8.     Protected Sub DeActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
  9.         Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)
  10.     End Sub
  11. </script>
  12.  
  13. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  14.     <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
  15.         <WizardSteps>
  16.             <asp:CreateUserWizardStep runat="server">
  17.             </asp:CreateUserWizardStep>
  18.             <asp:WizardStep runat="server" Title="Choose Account Type" OnActivate="ActivateStep" OnDeactivate="DeActivateStep">
  19.                 Select Account Type:<br />
  20.                 <br />
  21.                 <asp:ListBox ID="ListBox1" runat="server" CssClass="normaltext"></asp:ListBox>
  22.             </asp:WizardStep>
  23.             <asp:CompleteWizardStep runat="server">
  24.             </asp:CompleteWizardStep>
  25.         </WizardSteps>
  26.     </asp:CreateUserWizard>
  27.  
  28.  
  29. </asp:Content> 
The problem is i dont want them to be able to add themseleves to the administrator role, but i couldnt work out another way to get the roles and assign them, i found a tutorial that got me this far but now im stuck, your help would be greatly appreciated

Thanks
Apr 21 '07 #6
Frinavale
9,735 Expert Mod 8TB
Hi As per the last message ive now got some code together and it works, im trying to let the user select there account type during registration so i can structure content dependent on the role, the problem i now have is that i have 4 roles, Administrator, Customer, Landscaper, Wholesales, Code below.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3.     Protected Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
  4.         ListBox1.DataSource = Roles.GetAllRoles()
  5.         ListBox1.DataBind()
  6.     End Sub
  7.  
  8.     Protected Sub DeActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
  9.         Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)
  10.     End Sub
  11. </script>
  12.  
  13. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  14.     <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
  15.         <WizardSteps>
  16.             <asp:CreateUserWizardStep runat="server">
  17.             </asp:CreateUserWizardStep>
  18.             <asp:WizardStep runat="server" Title="Choose Account Type" OnActivate="ActivateStep" OnDeactivate="DeActivateStep">
  19.                 Select Account Type:<br />
  20.                 <br />
  21.                 <asp:ListBox ID="ListBox1" runat="server" CssClass="normaltext"></asp:ListBox>
  22.             </asp:WizardStep>
  23.             <asp:CompleteWizardStep runat="server">
  24.             </asp:CompleteWizardStep>
  25.         </WizardSteps>
  26.     </asp:CreateUserWizard>
  27.  
  28.  
  29. </asp:Content> 
The problem is i dont want them to be able to add themseleves to the administrator role, but i couldnt work out another way to get the roles and assign them, i found a tutorial that got me this far but now im stuck, your help would be greatly appreciated

Thanks

What is your Role's object type and could you post the code for the GetAllRoles() method.

Thanks
Apr 21 '07 #7
What is your Role's object type and could you post the code for the GetAllRoles() method.

Thanks
Thanks for being patient and replying but was able to do it myself, i changed my approach slightly and have pasted my code up incase its useful to any other newbie like me in the future. Thanks to the guys that replied

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3.     Protected Sub cuwUser_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs)
  4.         Roles.AddUserToRole(cuwUser.UserName, DropDownList1.SelectedValue)
  5.     End Sub
  6. </script>
  7.  
  8. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  9.     <asp:CreateUserWizard ID="cuwUser" runat="server">
  10.         <WizardSteps>
  11.             <asp:CreateUserWizardStep runat="server">
  12.             </asp:CreateUserWizardStep>
  13.             <asp:WizardStep runat="server" Title="Accout Type" OnDeactivate="cuwUser_CreatedUser1">
  14.                 Select Account Type:<br />
  15.                 <br />
  16.                 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
  17.                     DataTextField="RoleName" DataValueField="RoleName">
  18.                 </asp:DropDownList>
  19.                 <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringAccountType %>"
  20.                     SelectCommand="SELECT [RoleName] FROM [vw_aspnet_Roles] WHERE ([RoleName] NOT LIKE '%' + @RoleName + '%')">
  21.                     <SelectParameters>
  22.                         <asp:Parameter DefaultValue="Administrator" Name="RoleName" Type="String" />
  23.                     </SelectParameters>
  24.                 </asp:SqlDataSource>
  25.             </asp:WizardStep>
  26.             <asp:CompleteWizardStep runat="server">
  27.             </asp:CompleteWizardStep>
  28.         </WizardSteps>
  29.     </asp:CreateUserWizard>
  30.  
  31.  
  32. </asp:Content>
I decided to drop the GetAllRoles() Method, its not mine and is part of .net 2.0 and visual studio library but its really useful but i couldnt modify that, instead i added an sqldatasource for the roles table and bound this to a drop down, i then added the sql query so that it wouldnt show anything with administrator,
Apr 22 '07 #8
Frinavale
9,735 Expert Mod 8TB
Thanks for being patient and replying but was able to do it myself, i changed my approach slightly and have pasted my code up incase its useful to any other newbie like me in the future. Thanks to the guys that replied

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3.     Protected Sub cuwUser_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs)
  4.         Roles.AddUserToRole(cuwUser.UserName, DropDownList1.SelectedValue)
  5.     End Sub
  6. </script>
  7.  
  8. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  9.     <asp:CreateUserWizard ID="cuwUser" runat="server">
  10.         <WizardSteps>
  11.             <asp:CreateUserWizardStep runat="server">
  12.             </asp:CreateUserWizardStep>
  13.             <asp:WizardStep runat="server" Title="Accout Type" OnDeactivate="cuwUser_CreatedUser1">
  14.                 Select Account Type:<br />
  15.                 <br />
  16.                 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
  17.                     DataTextField="RoleName" DataValueField="RoleName">
  18.                 </asp:DropDownList>
  19.                 <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringAccountType %>"
  20.                     SelectCommand="SELECT [RoleName] FROM [vw_aspnet_Roles] WHERE ([RoleName] NOT LIKE '%' + @RoleName + '%')">
  21.                     <SelectParameters>
  22.                         <asp:Parameter DefaultValue="Administrator" Name="RoleName" Type="String" />
  23.                     </SelectParameters>
  24.                 </asp:SqlDataSource>
  25.             </asp:WizardStep>
  26.             <asp:CompleteWizardStep runat="server">
  27.             </asp:CompleteWizardStep>
  28.         </WizardSteps>
  29.     </asp:CreateUserWizard>
  30.  
  31.  
  32. </asp:Content>
I decided to drop the GetAllRoles() Method, its not mine and is part of .net 2.0 and visual studio library but its really useful but i couldnt modify that, instead i added an sqldatasource for the roles table and bound this to a drop down, i then added the sql query so that it wouldnt show anything with administrator,
Good job :)

Thanks for updating us!

-Frinny
Apr 23 '07 #9
Just edit the section
Expand|Select|Wrap|Line Numbers
  1.  if (AvailableRoles.Items[i].Selected == true)
  2.                 Roles.AddUserToRole(CreateUserWizard2.UserName, AvailableRoles.Items[i].Value);
  3.  
  4.   To THIS CODE 
  5. If admin is selected  in place of Admin  a default local role will be added
  6.  if (AvailableRoles.Items[i].Selected == true)
  7.             { 
  8.  
  9.                 if (AvailableRoles.Items[i].Text != "admin")
  10.                 {
  11.                     Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items[i].Value);
  12.                 }
  13.                 else
  14.                 {
  15.                     Roles.AddUserToRole(CreateUserWizard1.UserName, "Member");
  16.                 }
  17.             }
Dec 27 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: leecho | last post by:
Hi, I confuse. I had a role named lsc_role with certain object privs. if i run this query : select role from dba_role; ROLE ----------------------- JAVADEBUGPRIV EJBCLIENT JAVA_ADMIN
2
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some...
2
by: Spondishy | last post by:
Hi, I'm just getting into asp.net 2 c# using the login and registration controls. I have a role called publisher and want the user adding to that role when they register and send an email to say...
8
by: Mark White | last post by:
Hey everyone I'm having a great deal of problems finding this information through google and yahoo, so I turn to you on this. I have a Windows app running on XP. I am able to caputre the...
1
by: ^MisterJingo^ | last post by:
Hi all, I've been searching the net for a way to programatically add a user to a role on successful registration. Not finding anything useful I decided to experiment and came up with the...
6
by: dotNeter | last post by:
The services, talked here, are things used in IServiceContainer, IServiceProvider, etc. In my opinion, everything can be a service, and a service is generally used for providing specific features...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
8
by: | last post by:
I'm looking for some design guidance on a collection of projects I'm working on. The project involves a bunch of websites constructed out of a collection of user controls. Different user...
2
by: Anthony Smith | last post by:
I have a user object that is set when a user logs in. There are also permissions that I get about the user from a web service. Currently I take the results from those web services and store them as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.