用于用户管理的管理员页面 [英] Administrator pages for user management

查看:99
本文介绍了用于用户管理的管理员页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!我是一名学生.我的任务是使用以下命令制作ASP.NET网站:

1)明确角色的用户(管理员,来宾等)可以访问的页面-我借助于web.config文件通过目录保护来实现该页面;

2)用于用户管理的Administrotor页面

3)用户注册的可能性-我是通过CreateUserWizard控件实现的.

问题是我应该如何实现用于用户管理的administrotor页面?

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?

推荐答案

尊敬的Zhenyaa


请访问以下网站: http://weblogs.asp.net/scottgu/archive/2005 /10/18/427754.aspx [ ^ ].明确指定了使用角色和配置文件系统"创建和使用登录"控件.
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.


谢谢.但是我在此站点中的代码存在问题.

文件CreateNewWizard.aspx:
--------------------------------
]]>



< title>创建新用户



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 ="该帐户已成功创建.
UnknownErrorMessage =未创建帐户.请重试."
OnCreatedUser ="CreateUserWizard1_CreatedUser">

< wizardsteps>

< asp:createuserwizardstep id ="CreateUserWizardStep1" runat ="server" title =步骤1:基本用户信息">
< contenttemplate>


< asp:label id ="UserNameLabel" runat ="server" relatedcontrolid ="UserName"> UserID: < asp:textbox id ="UserName" runat ="server">
< asp:requiredfieldvalidator id ="UserNameRequired" runat ="server"工具提示=需要用户名.">
"ErrorMessage ="用户名是必需的. ValidationGroup ="CreateUserWizard1" ControlToValidate ="UserName">
*
< asp:label id ="PasswordLabel" runat ="server" relatedcontrolid ="Password">密码: < asp:textbox id ="Password" runat ="server" textmode ="Password">
< asp:requiredfieldvalidator id ="PasswordRequired" runat ="server"工具提示=需要密码.">
"ErrorMessage ="需要密码."ValidationGroup ="CreateUserWizard1" ControlToValidate ="Password">
*
< asp:label id ="ConfirmPasswordLabel" runat ="server" relatedcontrolid ="ConfirmPassword">重新输入密码:
< asp:textbox id ="ConfirmPassword" runat ="server" textmode ="Password">
< asp:requiredfieldvalidator id ="ConfirmPasswordRequired" runat ="server"工具提示=确认密码是必需的.">
"ErrorMessage ="确认密码是必需的."ValidationGroup ="CreateUserWizard1"
ControlToValidate ="ConfirmPassword">
*
< asp:label id ="EmailLabel" runat ="server" relatedcontrolid ="Email">电子邮件:
< asp:textbox id ="Email" runat ="server">
< asp:requiredfieldvalidator id ="EmailRequired" runat ="server"工具提示=需要电子邮件.">
"ErrorMessage ="电子邮件是必需的."ValidationGroup ="CreateUserWizard1" ControlToValidate =电子邮件">
*










安全问题:
< asp:dropdownlist id =问题" runat =服务器" width ="200">
< asp:listitem text ="[选择问题]">
< asp:listitem text =收藏宠物">
< asp:listitem text =母亲的娘家姓">
< asp:listitem text =您的童年英雄是谁?">
< asp:listitem text =您最喜欢的过去时间?">


< asp:requiredfieldvalidator id ="QuestionRequired" runat ="server" initialvalue ="[选择问题]" controltovalidate ="Question">
ErrorMessage =选择安全性问题" ValidationGroup ="CreateUserWizard1"> *
您的答案:
< asp:textbox id ="Answer" runat ="server">
< asp:requiredfieldvalidator id ="AnswerRequired" runat ="server" controltovalidate ="Answer">
ErrorMessage ="RequiredFieldValidator" ValidationGroup ="CreateUserWizard1"> *









国家/地区: < asp:dropdownlist id ="Country" runat ="server">
< asp:listitem text ="[选择国家/地区]">
< asp:listitem text =阿尔巴尼亚">
< asp:listitem text =奥地利">
< asp:listitem text ="Austrailia">
< asp:listitem text ="Belgium">
< asp:listitem text ="Other">


< asp:requiredfieldvalidator id ="RequiredFieldValidator1" runat ="server" initialvalue ="[选择国家/地区]" controltovalidate ="Country">
ErrorMessage =选择国家/地区" ValidationGroup ="CreateUserWizard1"> *
性别: < asp:dropdownlist id ="Gender" runat ="server">
< asp:listitem text ="[选择性别]">
< asp:listitem text ="Male">
< asp:listitem text ="Female">


< asp:requiredfieldvalidator id ="RequiredFieldValidator2" runat ="server" initialvalue ="[选择性别]" controltovalidate ="Gender">
ErrorMessage =选择性别" ValidationGroup ="CreateUserWizard1"> *
年龄: < asp:textbox id ="Age" runat ="server">

< asp:requiredfieldvalidator id ="RequiredFieldValidator3" runat ="server" controltovalidate ="Age">
ErrorMessage =输入年龄" ValidationGroup ="CreateUserWizard1"> *

< asp:rangevalidator id ="RangeValidator1" type ="Integer" controltovalidate ="Age" minimumvalue ="1" maximumvalue ="120" runat ="server" validationgroup ="CreateUserWizard1" errormessage =无效数字"> *
< asp:comparevalidator id ="PasswordCompare" runat ="server" errormessage =密码和确认密码必须匹配. >
ValidationGroup ="CreateUserWizard1" ControlToValidate ="ConfirmPassword" ControlToCompare =密码"
Display =动态">

< asp:文字ID ="ErrorMessage" runat ="server" enableviewstate ="False >




< asp:wizardstep runat ="server" id ="wsAssignUserToRoles" allowreturn ="False" title =步骤2:将用户分配给角色">
OnActivate ="AssignUserToRoles_Activate" OnDeactivate ="AssignUserToRoles_Deactivate">

为用户选择一个或多个角色:
< 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">









<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">










文件CreateNewWizard.aspx.cs:
-------------------------------------------------- -------------------------
使用系统;
使用System.Data;
使用System.Configuration;
使用System.Collections;
使用System.Collections.Generic;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;

公共局部类CreateNewWizard:System.Web.UI.Page {

//成功创建新用户时调用CreatedUser事件
public void CreateUserWizard1_CreatedUser(object sender,EventArgs e){

//为新创建的用户创建一个空的个人资料
ProfileCommon p =(ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName,true);

//从创建用户向导中填充一些配置文件属性
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);

//保存配置文件-必须完成,因为我们明确创建了此配置文件实例
p.Save();
}

//当用户在CreateUserWizard中点击下一步"时激活事件触发 公共无效AssignUserToRoles_Activate(对象发送者,EventArgs e){

//将角色管理器系统中的角色列表绑定到向导中的列表框
AvailableRoles.DataSource = Roles.GetAllRoles(); ;
AvailableRoles.DataBind();
}

//当用户在CreateUserWizard中点击下一步"时,停用事件触发
公共无效AssignUserToRoles_Deactivate(对象发送者,EventArgs e){

//将用户添加到从角色列表框中选择的所有角色
for(int i = 0; i< AvailableRoles.Items.Count; i ++){
如果(AvailableRoles.Items [i] .Selected == true)
Roles.AddUserToRole(CreateUserWizard1.UserName,AvailableRoles.Items [i] .Value);
}
}
}

错误:1.当前上下文中不存在名称"CreateUserWizard1"
2.错误17当前上下文中不存在名称"AvailableRoles"

有什么建议吗?






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?


这篇关于用于用户管理的管理员页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆