原文发布时间为:2008-07-30 —— 来源于本人的百度文章 [由搬家工具导入]

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 admin_rolegroup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {          
            ListBox1.DataSource = Membership.GetAllUsers();
            ListBox1.DataBind();
            ListBox2.DataSource = Roles.GetAllRoles();
            ListBox2.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string user = ListBox1.SelectedValue;
        string role = ListBox2.SelectedValue;

        if (!Roles.IsUserInRole(user, role))
        {
            Roles.AddUserToRole(user, role);
        }
        else
        {
            Response.Write("user is in the role");
        }
        ListBox3.DataSource = Roles.GetUsersInRole(role);
        ListBox3.DataBind();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        if(ListBox3.Items.Count>0)
        {
            string user = ListBox3.SelectedValue;
            string role = ListBox2.SelectedValue;

            if(Roles.IsUserInRole(user,role))
            {
                Roles.RemoveUserFromRole(user,role);
            }
            else
            {
                Response.Write("user is not in the role");
            }
            ListBox3.DataSource = Roles.GetUsersInRole(role);
            ListBox3.DataBind();
        }
    }
protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
    string role=ListBox2.SelectedValue;
    ListBox3.DataSource=Roles.GetUsersInRole(role);
    ListBox3.DataBind();
}
}

-------------------------------------------------------------------------------------------------

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 admin_role : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ListBox1.DataSource = Roles.GetAllRoles();
            ListBox1.DataBind();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Roles.CreateRole(TextBox1.Text);
        ListBox1.Items.Add(TextBox1.Text);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Roles.DeleteRole(ListBox1.SelectedValue);
        ListBox1.Items.Remove(ListBox1.SelectedItem);
    }
}

net6:用户添加到角色和移出角色,角色的创建与删除等Roles与Membership的使用的更多相关文章

  1. Maven-007-Nexus 用户添加,用户角色分配,用户修改密码,管理员重置用户密码

    配置好 maven nexus 私服后,默认的用户可通过查看[Users]查看当前私服中所存在的用户,如下图所示:

  2. SqlServer 添加用户 添加角色 分配权限

    转载自:https://www.cnblogs.com/accumulater/p/6158387.html   --创建一个简单的登录,登录名为:newlogin:登录密码:123456:默认数据库 ...

  3. MVC5 网站开发之七 用户功能 2 用户添加和浏览

    目录 MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 MVC5 网站开发之三 数据存储层功能实现 MVC5 网站开发之四 业务逻辑层的架构和基本功能 MVC5 网站开发之五 展示层架 ...

  4. 使用Asp.Net Core Identity给用户添加及删除角色

    基于Asp.Net Core编制一个项目,需要给用户添加及删除角色的功能,于是使用到了Identity中的UserManager. 先后解决了几个问题,终于实现了设想. 1. 环境条件 Asp.Net ...

  5. kubernetes dashboard访问用户添加权限控制

    前面我们在kubernetes dashboard 升级之路一文中成功的将Dashboard升级到最新版本了,增加了身份认证功能,之前为了方便增加了一个admin用户,然后授予了cluster-adm ...

  6. UE4中创建第一、第三人称角色,并进行角色间的切换

    在游戏中经常会出现第一人称和第三人称的视角切换场景,笔者在这里简单介绍如何进行这步操作. 1.创建角色 在内容浏览器中添加2个Character蓝图,分别命名为FirstPersonalCharact ...

  7. RDIFramework.NET V3.3 WinForm版角色授权管理新增角色对操作权限项、模块起止生效日期的设置

    在实际应用在我们可能会有这样的需求,某个操作权限项(按钮)或菜单在某个时间范围内可以让指定角色访问.此时通过我们的角色权限扩展设置就可以办到. 在我们框架V3.3 WinForm版全新增加了角色权限扩 ...

  8. Linux将用户添加到组的指令

    原文:https://blog.csdn.net/youmatterhsp/article/details/80549683:           https://www.cnblogs.com/cl ...

  9. Linux给用户添加sudo权限

    一.linux给用户添加sudo权限: 有时候,linux下面运行sudo命令,会提示类似: xxxis not in the sudoers file.  This incident will be ...

随机推荐

  1. E​x​c​h​a​n​g​e​邮​箱​搭​建

    出现的问题: System.Runtime.InteropServices.COMException(0x8004020F): The server rejected one or more reci ...

  2. vue 点击下拉框

    data: { hide:false, zhi:"全部" }, <div class="item"> <div class="c2c ...

  3. vuePress的使用

    今天来玩一玩vuePress的使用,用markdown来编辑一个页面网站,这里谈论到了简单使用,细节可以去官网上去查看 开始安装 项目依赖 // package.json { "name&q ...

  4. 【贪心 计数 倍增】bzoj4458: GTY的OJ

    倍增写挂调了半个晚上 Description 身为IOI金牌的gtyzs有自己的一个OJ,名曰GOJ.GOJ上的题目可谓是高质量而又经典,他在他的OJ里面定义了一个树形的分类目录,且两个相同级别的目录 ...

  5. Centos7系统下安装Docker

    1.确定你的Linux系统是Centos7 命令:cat /etc/redhat-release 2.yum安装gcc相关 1.配置好Centos7能上外网. 2.yum -y install gcc ...

  6. 局域网映射到公网-natapp实现

    在开发时可能会有这样的需求: 需要将自己开发的机器上的应用提供到公网上进行访问,但是并不想通过注册域名.搭建服务器等等一系列繁琐的操作来实现. 例如:微信公众号的开发调试就需要用到域名访问本机项目. ...

  7. phpExcel使用方法二

    require_once './phpexcel/PHPExcel.php'; // 首先创建一个新的对象 PHPExcel object $objPHPExcel = new PHPExcel(); ...

  8. 【php】 phpword下载文件问题

    这个问题是在 科锐国际 工作过程中发现的 word文档的名字(有汉字和空格)在windows系统上遍历是查不到文件的,但是在linux系统上市可以的压缩包里面的中文名word文档,如果出现汉字和空格, ...

  9. Python自定义一个数组类,支持数组之间的四则运算和其他常见方法

    class MyArray: '''保证输入的内容是整型.浮点型''' def ___isNumber(self, num): if not isinstance(num, (int,float)): ...

  10. vim中,在编辑模式下如何快速移动光标

    编辑 ~/.vimrc 配置文件,加入如下行,编辑模式下自定义的快捷键 inoremap <C-o> <Esc>o  inoremap <C-l> <Righ ...