nbsp; Response.Redirect(“~/CreatingUsers.aspx”);
}
else
{
lblReult.Visible=True;
lblReult.Text=”这个用户不能被删除”;
}
<五>更新用户信息
(1) 数据源的定义
<asp:ObjectDataSource ID=”ObjectDataSource1” runat=”server”
DataObjectTypeName=”System.Web.Security.MemberhipUser”
SelectMethod=”GetUser”
TypeName=”System.Web.Security.Membership”/>
(2) 显示用户数据的控件
<asp:DetialsView AutoGenerateRows=”False” DataSourceID=”ObjectDataSource1”
ID=”DetalisView1” runat=”server” AutoGeneratiEditButton=”true”
OnItemUpdating=”DatailsView_ItemUpdating”>
<Fields>
<asp:BindField DataField=”CretionDate” HeaderText=”CreationDate”
ReadOnly=”true” SortExpression=”CreationDate”/>
<asp:BindField DataField=”Comment” HeaderText=”Comment”
ReadOnly=”true” SortExpression=”Comment”/>
<asp:BindField DataField=”ProviderName” HeaderText=”ProviderName”
ReadOnly=”true” SortExpression=”ProviderName”/>
…………..
</Field>
</asp:DetialsView>
private void DetailsView1-ItemUpdating(Object Sender,DetailsViewUpdateEventArgs e)
{
MembershipUser memUser=Memberhip.GetUser();
MemUser.Email=e.NewValues(0).ToString();
MemUser.Comment=e.NewValues(1).ToString();
Memberhip.UpdateUser(memUser);
e.Cancel=true;
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
}
<六>用户的解锁
MembershipUser memUser=Membership.GetUser(txtUserName.text);
If(!memUser is Nothing &&memUer.IsLockedOut= =true)
{
memUer.UnlockUser();
}
DetailsView1.DataBind();
Private void Page_Load(Object sender,System.EventArg e)
{
if (!Page.IspostBack)
{
txtUserName.Text=User.Identity.Name;
}
}
<七>角色的添加
Roles.CreateRole(txtCreateRole.Text);
<八>角色的删除
Roles.DeleteRole(listboxRoles.SelectedValue);
<九>在列表中添加所有的角色。
ListboxRoles.DataSource=Roles.GetAllRoles();
<十>查看角色是否存在
Roles.RoleExists(“Administrators”);