角色管理功能:

界面部分:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="jueseadmin.aspx.cs" Inherits="admin_jueseadmin" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">

    <div>
<h1>角色管理</h1>
<div>
<h2>角色创建
</h2>
<asp:Panel ID="Panel2" runat="server">
<div>
<p>
角色创建
</p>
<div>
角色名称:<asp:TextBox ID="TextBoxRoleName" runat="server"></asp:TextBox>
<asp:Button ID="ButtonRolechuangjian" runat="server" Text="创建角色" OnClick="ButtonRolechuangjian_Click" ValidationGroup="cjjs" />
<br />
<asp:Label ID="Labelcjts" runat="server"></asp:Label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxRoleName" CssClass="text-warning" ErrorMessage="RequiredFieldValidator" ValidationGroup="cjjs">您未输入需创建的角色名称。</asp:RequiredFieldValidator>
</div>
</div>
</asp:Panel>
<hr />
<asp:Panel ID="Panel1" runat="server">
<div>
<p>
角色分配
</p>
<div>
用户名称:<asp:TextBox ID="yonghumingcheng" runat="server"></asp:TextBox>
角色名称:<asp:TextBox ID="juesemingcheng" runat="server"></asp:TextBox>
<asp:Button ID="Buttonjuesefenpei" runat="server" Text="划入角色" OnClick="Buttonjuesefenpei_Click" ValidationGroup="hrjs" />
<br />
<asp:Label ID="Labelhrts" runat="server"></asp:Label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator" CssClass="text-warning" ControlToValidate="yonghumingcheng" ValidationGroup="hrjs">您未输入用户名称。</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="RequiredFieldValidator" CssClass="text-warning" ControlToValidate="juesemingcheng" ValidationGroup="hrjs">您未输入角色名称。</asp:RequiredFieldValidator>
</div>
</div>
</asp:Panel>
<hr />
<asp:Panel ID="Panel3" runat="server">
<div>
<p>
删除角色
</p>
<div>
角色名称:<asp:TextBox ID="TextBoxjueseshanchu" runat="server"></asp:TextBox>
<asp:Button ID="Buttonjueseshanchu" runat="server" Text="删除角色" OnClick="Buttonjueseshanchu_Click" ValidationGroup="scjs" />
<br />
<asp:Label ID="Labelscts" runat="server"></asp:Label>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBoxjueseshanchu" CssClass="text-warning" ErrorMessage="RequiredFieldValidator" ValidationGroup="scjs">您未输入需创建的角色名称。</asp:RequiredFieldValidator>
</div>
</div>
</asp:Panel>
</div>
</div> </asp:Content>

cs代码部分:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using xxxxform; //你的项目 public partial class admin_jueseadmin : System.Web.UI.Page
{
ApplicationDbContext context = new ApplicationDbContext();
IdentityResult IdRoleResult;
IdentityResult IdUserResult;
protected void Page_Load(object sender, EventArgs e)
{ }
protected void ButtonRolechuangjian_Click(object sender, EventArgs e)
{
var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);
if (!roleManager.RoleExists(TextBoxRoleName.Text))
{
var IdRoleResult = roleManager.Create(new IdentityRole { Name = TextBoxRoleName.Text });
Labelcjts.Text = "角色已经创建完成";
}
else
{
Labelcjts.Text = "该角色已存在,无需创建。";
}
} protected void Buttonjuesefenpei_Click(object sender, EventArgs e)
{
var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
if (!userManager.IsInRole(userManager.FindByName(yonghumingcheng.Text).Id, juesemingcheng.Text))
{
IdUserResult = userManager.AddToRole(userManager.FindByName(yonghumingcheng.Text).Id, juesemingcheng.Text);
Labelhrts.Text = "用户划入角色完成";
}
} protected void Buttonjueseshanchu_Click(object sender, EventArgs e)
{
var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);
IdRoleResult = roleManager.Delete(new IdentityRole { Name = TextBoxjueseshanchu.Text });
Labelcjts.Text = "角色已经删除完成";
}
}

asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(三)的更多相关文章

  1. asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(一)

    基本环境:asp.net 4.5.2 仔细看了在Webform下,模板就已经启动了角色控制,已经不用再进行设置了.直接调用相关类就可以了.这和原来在网站根目录下配置Web.config完全不同了. 相 ...

  2. asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(二)

    管理用户功能: 界面部分: <%@ Page Title="" Language="C#" MasterPageFile="~/Site.mas ...

  3. asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(四)

    有网友问及权限的问题,其实我觉得没什么改进. 主目录下的web.config基本不用改.要说要改的也就只有数据库连接了. <authentication mode="None" ...

  4. asp.net identity 2.2.0 在MVC下的角色启用和基本使用(一)

    基本环境:asp.net 4.5.2 第一步:在App_Start文件夹中的IdentityConfig.cs中添加角色控制器. 在namespace xxx内(即最后一个“}”前面)添加 角色控制类 ...

  5. Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理

    这是本人第一次写,写的不好的地方还忘包含.写这个的主要原因是想通过这个来学习下EF的CodeFirst模式,本来也想用AngularJs来玩玩的,但是自己只会普通的绑定,对指令这些不是很熟悉,所以就基 ...

  6. asp.net identity 2.2.0 中角色启用和基本使用(七)提示点

    在使用asp.net identity 2.2.0 中,大家可能设计到一些修改和配置 关于Identity的配置,在App_Start文件中的IdentityConfig.cs中,这里几乎有你需要的一 ...

  7. asp.net identity 2.2.0 中角色启用和基本使用(六)

    创建用户管理相关视图 第一步:添加视图   打开UsersAdminController.cs   将鼠标移动到public ActionResult Index()上  右键>添加视图   系 ...

  8. Owin+ASP.NET Identity浅析系列(四)实现用户角色

    在今天,读书有时是件“麻烦”事.它需要你付出时间,付出精力,还要付出一份心境.--仅以<Owin+ASP.NET Identity浅析系列>来祭奠那逝去的…… 通过Owin+ASP.NET ...

  9. asp.net identity 2.2.0 中角色启用和基本使用(三)

    创建控制器 第一步:在controllers文件夹上点右键>添加>控制器, 我这里选的是“MVC5 控制器-空”,名称设置为:RolesAdminController.cs 第二步:添加命 ...

随机推荐

  1. 微信支付 发布后显示 System:access_denied

    微信支付发布后显示 System:access_denied (android)或 System:not_allow(IOS) 我们项目用的是.NET MVC3 授权目录是:http://mynetd ...

  2. python之路十

    协程协程,又称微线程,纤程.英文名Coroutine.一句话说明什么是线程:协程是一种用户态的轻量级线程.协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文和栈保存到其他地方,在切回来的时 ...

  3. core dump 是什么意思?

    core dump,翻译过来讲,就是核心转储.大致上就是指,如果由于应用错误,如浮点异常.指令异常等,操作系统将会转入内核的异常处理,向对应的进程发送特定的信号(SIGNAL),如果进程中没有对这些信 ...

  4. Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 public cl ...

  5. MVC4.0

    --后台ajax传值 <script type="text/javascript">     $(document).ready(function dianZan(id ...

  6. 基于Z-WAVE 协议的LED智能照明系统的研究笔记

    LED调光基础: ☆:LED照明调光控制信号的方式有两种: 1. 通过PWM信号控制LED灯具开关电源的占空比从而实现调光: 2. 通过调光控制信号和交流电源供电线合用的两线式或三线式(例如LED相控 ...

  7. OUC校园导游

    大二专业课太多,都没有好好的在博客上面做笔记,以备后面用的时候可以查找看一下,下面是写的不是完全正确的与图相关的代码~~希望指正~~ /* Name: Copyright: Author:Hxm Da ...

  8. Android笔记:调试android程序

    1.Debug 第一步: 添加断点 第二步: 右击项目→Debug As→Android Application  //之后一个对话框出现,一会自动消失 第三步: 执行手机端操作,Eclipse 就会 ...

  9. http升https笔记

    证书申请的: 1.lets encrypt 国际公益项目发展很快的,不过在国内暂时有些支持度还不够高,如微信安卓版就不认lets encrypt的证书.跳转进去一直处于空白页状态 2.沃通证书  国内 ...

  10. python开发目录合并小工具 PathMerge

    前言 这个程序陆陆续续开发了几天,正好我在学Python,就一边做一边学,倒是学到不少东西. 不得不说python是快速开发的好工具. 程序做了一些改进,这两天又忙着毕设,现在才想起来发到博客上.想想 ...