日期:2014-05-17 浏览次数:20604 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class ShowSecurityTrimming : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
foreach (ListItem item in cbl.Items)
{
if (!Roles.RoleExists(item.Text))
{
Roles.CreateRole(item.Text);
Roles.AddUserToRole(User.Identity.Name, item.Text);
}
}
}
protected void btn_Click(object sender, EventArgs e)
{
foreach(ListItem item in cbl.Items)
{
if(item.Selected)
{
if(!User.IsInRole(item.Text))
Roles.AddUserToRole(User.Identity.Name,item.Text);
}
else
{
if(User.IsInRole(item.Text))
{
Roles.RemoveUserFromRole(User.Identity.Name,item.Text);
}
}
}
&