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
9 6541
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
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. - <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
-
<script runat="server">
-
Protected Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
-
ListBox1.DataSource = Roles.GetAllRoles()
-
ListBox1.DataBind()
-
End Sub
-
-
Protected Sub DeActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
-
Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)
-
End Sub
-
</script>
-
-
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
-
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
-
<WizardSteps>
-
<asp:CreateUserWizardStep runat="server">
-
</asp:CreateUserWizardStep>
-
<asp:WizardStep runat="server" Title="Choose Account Type" OnActivate="ActivateStep" OnDeactivate="DeActivateStep">
-
Select Account Type:<br />
-
<br />
-
<asp:ListBox ID="ListBox1" runat="server" CssClass="normaltext"></asp:ListBox>
-
</asp:WizardStep>
-
<asp:CompleteWizardStep runat="server">
-
</asp:CompleteWizardStep>
-
</WizardSteps>
-
</asp:CreateUserWizard>
-
-
-
</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
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. - <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
-
<script runat="server">
-
Protected Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
-
ListBox1.DataSource = Roles.GetAllRoles()
-
ListBox1.DataBind()
-
End Sub
-
-
Protected Sub DeActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
-
Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)
-
End Sub
-
</script>
-
-
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
-
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
-
<WizardSteps>
-
<asp:CreateUserWizardStep runat="server">
-
</asp:CreateUserWizardStep>
-
<asp:WizardStep runat="server" Title="Choose Account Type" OnActivate="ActivateStep" OnDeactivate="DeActivateStep">
-
Select Account Type:<br />
-
<br />
-
<asp:ListBox ID="ListBox1" runat="server" CssClass="normaltext"></asp:ListBox>
-
</asp:WizardStep>
-
<asp:CompleteWizardStep runat="server">
-
</asp:CompleteWizardStep>
-
</WizardSteps>
-
</asp:CreateUserWizard>
-
-
-
</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 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. - <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
-
<script runat="server">
-
Protected Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
-
ListBox1.DataSource = Roles.GetAllRoles()
-
ListBox1.DataBind()
-
End Sub
-
-
Protected Sub DeActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
-
Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)
-
End Sub
-
</script>
-
-
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
-
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
-
<WizardSteps>
-
<asp:CreateUserWizardStep runat="server">
-
</asp:CreateUserWizardStep>
-
<asp:WizardStep runat="server" Title="Choose Account Type" OnActivate="ActivateStep" OnDeactivate="DeActivateStep">
-
Select Account Type:<br />
-
<br />
-
<asp:ListBox ID="ListBox1" runat="server" CssClass="normaltext"></asp:ListBox>
-
</asp:WizardStep>
-
<asp:CompleteWizardStep runat="server">
-
</asp:CompleteWizardStep>
-
</WizardSteps>
-
</asp:CreateUserWizard>
-
-
-
</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
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. - <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
-
<script runat="server">
-
Protected Sub ActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
-
ListBox1.DataSource = Roles.GetAllRoles()
-
ListBox1.DataBind()
-
End Sub
-
-
Protected Sub DeActivateStep(ByVal sender As Object, ByVal e As System.EventArgs)
-
Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue)
-
End Sub
-
</script>
-
-
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
-
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
-
<WizardSteps>
-
<asp:CreateUserWizardStep runat="server">
-
</asp:CreateUserWizardStep>
-
<asp:WizardStep runat="server" Title="Choose Account Type" OnActivate="ActivateStep" OnDeactivate="DeActivateStep">
-
Select Account Type:<br />
-
<br />
-
<asp:ListBox ID="ListBox1" runat="server" CssClass="normaltext"></asp:ListBox>
-
</asp:WizardStep>
-
<asp:CompleteWizardStep runat="server">
-
</asp:CompleteWizardStep>
-
</WizardSteps>
-
</asp:CreateUserWizard>
-
-
-
</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
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 - <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
-
<script runat="server">
-
Protected Sub cuwUser_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs)
-
Roles.AddUserToRole(cuwUser.UserName, DropDownList1.SelectedValue)
-
End Sub
-
</script>
-
-
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
-
<asp:CreateUserWizard ID="cuwUser" runat="server">
-
<WizardSteps>
-
<asp:CreateUserWizardStep runat="server">
-
</asp:CreateUserWizardStep>
-
<asp:WizardStep runat="server" Title="Accout Type" OnDeactivate="cuwUser_CreatedUser1">
-
Select Account Type:<br />
-
<br />
-
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
-
DataTextField="RoleName" DataValueField="RoleName">
-
</asp:DropDownList>
-
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringAccountType %>"
-
SelectCommand="SELECT [RoleName] FROM [vw_aspnet_Roles] WHERE ([RoleName] NOT LIKE '%' + @RoleName + '%')">
-
<SelectParameters>
-
<asp:Parameter DefaultValue="Administrator" Name="RoleName" Type="String" />
-
</SelectParameters>
-
</asp:SqlDataSource>
-
</asp:WizardStep>
-
<asp:CompleteWizardStep runat="server">
-
</asp:CompleteWizardStep>
-
</WizardSteps>
-
</asp:CreateUserWizard>
-
-
-
</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,
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 - <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
-
<script runat="server">
-
Protected Sub cuwUser_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs)
-
Roles.AddUserToRole(cuwUser.UserName, DropDownList1.SelectedValue)
-
End Sub
-
</script>
-
-
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
-
<asp:CreateUserWizard ID="cuwUser" runat="server">
-
<WizardSteps>
-
<asp:CreateUserWizardStep runat="server">
-
</asp:CreateUserWizardStep>
-
<asp:WizardStep runat="server" Title="Accout Type" OnDeactivate="cuwUser_CreatedUser1">
-
Select Account Type:<br />
-
<br />
-
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
-
DataTextField="RoleName" DataValueField="RoleName">
-
</asp:DropDownList>
-
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringAccountType %>"
-
SelectCommand="SELECT [RoleName] FROM [vw_aspnet_Roles] WHERE ([RoleName] NOT LIKE '%' + @RoleName + '%')">
-
<SelectParameters>
-
<asp:Parameter DefaultValue="Administrator" Name="RoleName" Type="String" />
-
</SelectParameters>
-
</asp:SqlDataSource>
-
</asp:WizardStep>
-
<asp:CompleteWizardStep runat="server">
-
</asp:CompleteWizardStep>
-
</WizardSteps>
-
</asp:CreateUserWizard>
-
-
-
</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
Just edit the section -
if (AvailableRoles.Items[i].Selected == true)
-
Roles.AddUserToRole(CreateUserWizard2.UserName, AvailableRoles.Items[i].Value);
-
-
To THIS CODE
-
If admin is selected in place of Admin a default local role will be added
-
if (AvailableRoles.Items[i].Selected == true)
-
{
-
-
if (AvailableRoles.Items[i].Text != "admin")
-
{
-
Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items[i].Value);
-
}
-
else
-
{
-
Roles.AddUserToRole(CreateUserWizard1.UserName, "Member");
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |