Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! I'm a student. I have a task to make ASP.NET site with:

1) pages, that are accessible for users of definite role (administrators, guests and so on) - I realize it through catalogue protect with the help of web.config file;

2) Administrotor pages for user management

3) possibility of user registration - I realize it with the help of CreateUserWizard control.

The question is how should I realize administrotor pages for user management?
Posted
Updated 19-Aug-10 1:34am
v2

Dear Zhenyaa


Please refer the site : http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx[^] for your requirement. It is clearly specified about creating and using the Login controls with Roles and Profile System.
 
Share this answer
 
Thank you. But I have the problem with code in this site.

File CreateNewWizard.aspx:
--------------------------------
]]>



<title>Create New User







<asp:createuserwizard id="CreateUserWizard1" runat="server" xmlns:asp="#unknown">
ContinueDestinationPageUrl="~/default.aspx"
DisableCreatedUser="false"
Font-Names="Verdana"
BackColor="white"
Font-Size="10pt"
BorderWidth="1px"
BorderColor="#CCCC99"
BorderStyle="Solid"
CompleteSuccessText="The account has been successfully created."
UnknownErrorMessage="The account was not created. Please try again."
OnCreatedUser="CreateUserWizard1_CreatedUser">

<wizardsteps>

<asp:createuserwizardstep id="CreateUserWizardStep1" runat="server" title="Step 1: Basic User Information">
<contenttemplate>


Create Your UserID
<asp:label id="UserNameLabel" runat="server" associatedcontrolid="UserName">UserID: <asp:textbox id="UserName" runat="server">
<asp:requiredfieldvalidator id="UserNameRequired" runat="server" tooltip="User Name is required.">
ErrorMessage="User Name is required." ValidationGroup="CreateUserWizard1" ControlToValidate="UserName">
*
<asp:label id="PasswordLabel" runat="server" associatedcontrolid="Password">Password: <asp:textbox id="Password" runat="server" textmode="Password">
<asp:requiredfieldvalidator id="PasswordRequired" runat="server" tooltip="Password is required.">
ErrorMessage="Password is required." ValidationGroup="CreateUserWizard1" ControlToValidate="Password">
*
<asp:label id="ConfirmPasswordLabel" runat="server" associatedcontrolid="ConfirmPassword">Re-Type Password:
<asp:textbox id="ConfirmPassword" runat="server" textmode="Password">
<asp:requiredfieldvalidator id="ConfirmPasswordRequired" runat="server" tooltip="Confirm Password is required.">
ErrorMessage="Confirm Password is required." ValidationGroup="CreateUserWizard1"
ControlToValidate="ConfirmPassword">
*
<asp:label id="EmailLabel" runat="server" associatedcontrolid="Email">Email:
<asp:textbox id="Email" runat="server">
<asp:requiredfieldvalidator id="EmailRequired" runat="server" tooltip="Email is required.">
ErrorMessage="Email is required." ValidationGroup="CreateUserWizard1" ControlToValidate="Email">
*










If You Forget Your Password
Security Question:
<asp:dropdownlist id="Question" runat="server" width="200">
<asp:listitem text="[Select a Question]">
<asp:listitem text="Favorite Pet">
<asp:listitem text="Mother's Maiden Name">
<asp:listitem text="Who was your childhood hero?">
<asp:listitem text="Your favorite pasttime?">


<asp:requiredfieldvalidator id="QuestionRequired" runat="server" initialvalue="[Select a Question]" controltovalidate="Question">
ErrorMessage="Select a Security Question" ValidationGroup="CreateUserWizard1">*
Your Answer:
<asp:textbox id="Answer" runat="server">
<asp:requiredfieldvalidator id="AnswerRequired" runat="server" controltovalidate="Answer">
ErrorMessage="RequiredFieldValidator" ValidationGroup="CreateUserWizard1">*









Help Us Customize Your Experience
Country: <asp:dropdownlist id="Country" runat="server">
<asp:listitem text="[Select a Country]">
<asp:listitem text="Albania">
<asp:listitem text="Austria">
<asp:listitem text="Austrailia">
<asp:listitem text="Belgium">
<asp:listitem text="Other">


<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" initialvalue="[Select a Country]" controltovalidate="Country">
ErrorMessage="Select a Country" ValidationGroup="CreateUserWizard1">*
Gender: <asp:dropdownlist id="Gender" runat="server">
<asp:listitem text="[Select Gender]">
<asp:listitem text="Male">
<asp:listitem text="Female">


<asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" initialvalue="[Select Gender]" controltovalidate="Gender">
ErrorMessage="Select Gender" ValidationGroup="CreateUserWizard1">*
Age: <asp:textbox id="Age" runat="server">

<asp:requiredfieldvalidator id="RequiredFieldValidator3" runat="server" controltovalidate="Age">
ErrorMessage="Enter Age" ValidationGroup="CreateUserWizard1">*

<asp:rangevalidator id="RangeValidator1" type="Integer" controltovalidate="Age" minimumvalue="1" maximumvalue="120" runat="server" validationgroup="CreateUserWizard1" errormessage="Not a valid number">*
<asp:comparevalidator id="PasswordCompare" runat="server" errormessage="The Password and Confirmation Password must match.">
ValidationGroup="CreateUserWizard1" ControlToValidate="ConfirmPassword" ControlToCompare="Password"
Display="Dynamic">

<asp:literal id="ErrorMessage" runat="server" enableviewstate="False">




<asp:wizardstep runat="server" id="wsAssignUserToRoles" allowreturn="False" title="Step 2: Assign User To Roles">
OnActivate="AssignUserToRoles_Activate" OnDeactivate="AssignUserToRoles_Deactivate">

Select one or more roles for the user:
<asp:listbox id="AvailableRoles" runat="server" selectionmode="Multiple" height="104px" width="264px">



<asp:completewizardstep id="CompleteWizardStep1" runat="server">



<titletextstyle font-bold="True" backcolor="#6B696B" forecolor="White">










File CreateNewWizard.aspx.cs:
---------------------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CreateNewWizard : System.Web.UI.Page {

// CreatedUser event is called when a new user is successfully created
public void CreateUserWizard1_CreatedUser(object sender, EventArgs e) {

// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon) ProfileCommon.Create(CreateUserWizard1.UserName, true);

// Populate some Profile properties off of the create user wizard
p.Country = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Country")).SelectedValue;
p.Gender = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Gender")).SelectedValue;
p.Age = Int32.Parse(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Age")).Text);

// Save the profile - must be done since we explicitly created this profile instance
p.Save();
}

// Activate event fires when the user hits "next" in the CreateUserWizard
public void AssignUserToRoles_Activate(object sender, EventArgs e) {

// Databind list of roles in the role manager system to a listbox in the wizard
AvailableRoles.DataSource = Roles.GetAllRoles(); ;
AvailableRoles.DataBind();
}

// Deactivate event fires when user hits "next" in the CreateUserWizard
public void AssignUserToRoles_Deactivate(object sender, EventArgs e) {

// Add user to all selected roles from the roles listbox
for (int i = 0; i < AvailableRoles.Items.Count; i++) {
if (AvailableRoles.Items[i].Selected == true)
Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items[i].Value);
}
}
}

Errors: 1. The name 'CreateUserWizard1' does not exist in the current context
2. Error 17 The name 'AvailableRoles' does not exist in the current context

Any suggestions?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900