Solved

How do I Assign role to new user with asp.net 2.0 CreateUserWizard

Posted on 2008-06-24
6
1,246 Views
Last Modified: 2013-12-16
I am trying to assign a role to my users when they signup. Im using the asp.net 2.0 CreateUserWizard.  It create the user, but does not assign the role.  Below is what i have for code.  Can some one show me what Im doing wrong?

Thanks for any help.

Code behind page:

protected void Page_Load(object sender, EventArgs e)
    {
 
    }
        protected void CreateUserWizard1_CreatedUser(
    object sender, EventArgs e)
    {  
         Roles.AddUserToRole(CreateUserWizard1.UserName, "Admin");
    }


html page:
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
            Height="195px" Width="367px">
            <WizardSteps>
                <asp:CreateUserWizardStep runat="server" />
                <asp:CompleteWizardStep runat="server" />
            </WizardSteps>
        </asp:CreateUserWizard>
0
Comment
Question by:bmanmike39
  • 3
  • 3
6 Comments
 
LVL 21

Expert Comment

by:naspinski
ID: 21863147
replace:
Roles.AddUserToRole(CreateUserWizard1.UserName, "Admin");

with
Response.Write(CreateUserWizard1.UserName);

to make sure it is sending the name you thought it was sending. This will also make sure this event is firing.
0
 

Author Comment

by:bmanmike39
ID: 21863192
I replaced the line of code.  It created the user but did not fire response redirect.
0
 
LVL 21

Expert Comment

by:naspinski
ID: 21863246
ok, so that event is never actually firing.  In your aspx, it does not look like your CreateUserWizard has this event declared?  Otherwise, that event won't get fired.

oncreateduser="CreateUserWizard1_CreatedUser"
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:bmanmike39
ID: 21863255
where do i put this code?  in page load?
0
 
LVL 21

Accepted Solution

by:
naspinski earned 500 total points
ID: 21863298
no, inside your CreateUserWIzard Control
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
            Height="195px" Width="367px"
            oncreateduser="CreateUserWizard1_CreatedUser">
            <WizardSteps>
                <asp:CreateUserWizardStep runat="server" />
                <asp:CompleteWizardStep runat="server" />
            </WizardSteps>
        </asp:CreateUserWizard>

Open in new window

0
 

Author Comment

by:bmanmike39
ID: 21863341
Thank it woked!!!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question