asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(三)
角色管理功能:
界面部分:
<%@ 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下的角色启用和基本使用(三)的更多相关文章
- asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(一)
基本环境:asp.net 4.5.2 仔细看了在Webform下,模板就已经启动了角色控制,已经不用再进行设置了.直接调用相关类就可以了.这和原来在网站根目录下配置Web.config完全不同了. 相 ...
- asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(二)
管理用户功能: 界面部分: <%@ Page Title="" Language="C#" MasterPageFile="~/Site.mas ...
- asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(四)
有网友问及权限的问题,其实我觉得没什么改进. 主目录下的web.config基本不用改.要说要改的也就只有数据库连接了. <authentication mode="None" ...
- asp.net identity 2.2.0 在MVC下的角色启用和基本使用(一)
基本环境:asp.net 4.5.2 第一步:在App_Start文件夹中的IdentityConfig.cs中添加角色控制器. 在namespace xxx内(即最后一个“}”前面)添加 角色控制类 ...
- Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理
这是本人第一次写,写的不好的地方还忘包含.写这个的主要原因是想通过这个来学习下EF的CodeFirst模式,本来也想用AngularJs来玩玩的,但是自己只会普通的绑定,对指令这些不是很熟悉,所以就基 ...
- asp.net identity 2.2.0 中角色启用和基本使用(七)提示点
在使用asp.net identity 2.2.0 中,大家可能设计到一些修改和配置 关于Identity的配置,在App_Start文件中的IdentityConfig.cs中,这里几乎有你需要的一 ...
- asp.net identity 2.2.0 中角色启用和基本使用(六)
创建用户管理相关视图 第一步:添加视图 打开UsersAdminController.cs 将鼠标移动到public ActionResult Index()上 右键>添加视图 系 ...
- Owin+ASP.NET Identity浅析系列(四)实现用户角色
在今天,读书有时是件“麻烦”事.它需要你付出时间,付出精力,还要付出一份心境.--仅以<Owin+ASP.NET Identity浅析系列>来祭奠那逝去的…… 通过Owin+ASP.NET ...
- asp.net identity 2.2.0 中角色启用和基本使用(三)
创建控制器 第一步:在controllers文件夹上点右键>添加>控制器, 我这里选的是“MVC5 控制器-空”,名称设置为:RolesAdminController.cs 第二步:添加命 ...
随机推荐
- Mysql数据库的使用总结之Innodb简介(一)
最近在对开发的软件的服务器部分制作安装包,但服务器部分需要有mysql数据库的支持.因此,采用免安装版的mysql策略:将mysql数据库需要的文件在安装程序中进行设置和打包即可.但也遇到了很多 ...
- JS 对数组的常用处理
首先写游戏的时候,JSON字符串转成OBJECT的时候,希望做个数组随机排序的方法如下: //用Math.random()函数生成0~1之间的随机数与0.5比较,返回-1或1 function ran ...
- GitHub团队项目合作流程
已在另一篇博客中写出关于以下问题的解决,点此进入: 同步团队项目到本地时出现冲突怎么办? 项目负责人merge一个Pull Request后发现有错怎么回退? 目录: 零.前期准备 一.创建开发分支 ...
- ngx_image_thumb模块生成缩略图
ngx_image_thumb是nginx中用来生成缩略图的模块. 编译前确定已经安装了libcurl-dev libgd2-dev libpcre-dev gd-devel pcre-devel l ...
- 为何Redis要比Memcached好用(转)
转载链接:http://blog.csdn.net/renfufei/article/details/40598889 GitHub版本地址: https://github.com/cncounter ...
- SVN-功能介绍之切换
当初新建项目IMyYa 提交到svn 目录下file:///H:/svn/truck/IMyYa 现在svn 目录版本库中调整为file:///H:/svn/truck/Win8/IMyYa 与之前不 ...
- 【leetcode】Two Sum
题目简述: Given an array of integers, find two numbers such that they add up to a specific target number ...
- 【CentOS】学习Bash
一.特性 命令历史 history , !! , !$ , !字符 , !n (n为第几条命令) Tab可以补全文件路径或者命令 alias a="b", unalias a ...
- Linux学习笔记(3)-常用命令
江湖传言,Linux和Windows不同,他主要的用途是在一些服务器,或者片内系统上,所以人机交互界面自然就没有Windows那么漂亮,其实也没有那个必要. 所以,学习Linux的第一步,就是学习他那 ...
- 数据类型和Json格式
1. 前几天,我才知道有一种简化的数据交换格式,叫做yaml. 我翻了一遍它的文档,看懂的地方不多,但是有一句话令我茅塞顿开. 它说,从结构上看,所有的数据(data)最终都可以分解成三种类型: 第一 ...