Solved

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

Posted on 2008-06-24
6
1,258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

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 …
Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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…

627 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