Solved

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

Posted on 2008-06-24
6
1,249 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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 choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

809 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