Solved

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

Posted on 2008-06-24
6
1,243 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now