看代码基本就都能看懂了,增加了两个用户详细信息的表,角色表增加两个字段页面中实现树形显示。

//IdentityModels.cs

using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework; namespace WebDemo20150801.Models
{
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
} public virtual UserSetting UsersSetting { get; set; }//增加两个表用来显示用户数据
public virtual UserInfo UsersInfo { get; set; } } public class UserSetting
{
public string Id { get; set; }
public string Theme { get; set; }
} public class UserInfo
{
public string Id { get; set; }
public string TrueName { get; set; }
public string Phone { get; set; }
} public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public ApplicationRole(string name) : base(name) { }
public ApplicationRole(string name, string description)
: this(name)
{
this.Description = description;
} public string Description { get; set; }//角色表里新增加的字段
public string ParentRole { get; set; }
} public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
} public new IDbSet<ApplicationRole> Roles { get; set; }//一定要重写这个方法,不然能用,网页中也能获取数据,就是代码里点不出来~~ public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
}

这是MVC5,MVC6看起来舒服多了,还能方便的修改ID为数字类型。

public class IdentityDbContext : IdentityDbContext<IdentityUser, IdentityRole, string> { }

但是现在的版本需要这样

    public class ApplicationDbContext
: IdentityDbContext<ApplicationUser, ApplicationRole,
string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>

所以我放弃吧ID改成数字了。

这有ID变为数字的代码

https://github.com/TypecastException/AspNet-Identity-2-With-Integer-Keys/blob/master/IdentitySample/Models/IdentityModels.cs

MVC5 Identity 自定义用户和角色的更多相关文章

  1. asp.net core系列 47 Identity 自定义用户数据

    一.概述 接着上篇的WebAppIdentityDemo项目,将自定义用户数据添加到Identity DB,自定义扩展的用户数据类应继承IdentityUser类, 文件名为Areas / Ident ...

  2. .NET 实现自定义ContextUser的Identity和Principal实现自定义用户信息,权限验证。

    备用收藏,http://blog.csdn.net/msdnxgh/article/details/6894885 .NET 实现自定义ContextUser的Identity和Principal 在 ...

  3. SpringSecurity 自定义用户 角色 资源权限控制

    SpringSecurity 自定义用户 角色 资源权限控制 package com.joyen.learning.security; import java.sql.ResultSet; impor ...

  4. Identity角色管理五(添加用户到角色组)

    因需要在用户列表中点详情按钮来到当前页,所以需要展示分组详情,并展示当前所属角色组的用户 public async Task<ActionResult> Details(string id ...

  5. ASP.NET MVC5+EF6+EasyUI 后台管理系统(27)-权限管理系统-分配用户给角色

    系列目录 分配用户给角色,跟分配角色给用户操作是基本一致的. 打开模块维护,展开SysRole模块添加一个操作码,并赋予权限 设置好之后将权限授权给管理员,在SysRole的index添加操作码与js ...

  6. 基于FormsAuthentication的用户、角色身份认证

    一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到 Session中存储的用户基本信息,查看比较他有没有登录和能否 ...

  7. MVC5+EF6 --自定义控制Action访问权限

    本章主要讲解在MVC中灵活控制Action的访问权限: 本章所使用的示例表也是上一张所使用的TbUser.TbRole.TbUserRole: 最终的效果是针对任意一个Action或Controlle ...

  8. 基于FormsAuthentication的用户、角色身份认证(转)

    一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到 Session中存储的用户基本信息,查看比较他有没有登录和能否 ...

  9. ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core

    前言 原本本节内容是不存在的,出于有几个人问到了我:我想使用ASP.NET Core Identity,但是我又不想使用默认生成的数据库表,想自定义一套,我想要使用ASP.NE Core Identi ...

随机推荐

  1. SQL Server 2005中的分区表(二):如何添加、查询、修改分区表中的数据(转)

    在创建完分区表后,可以向分区表中直接插入数据,而不用去管它这些数据放在哪个物理上的数据表中.接上篇文章,我们在创建好的分区表中插入几条数据 insert Sale ([Name],[SaleTime] ...

  2. delphi中使用spcomm来实现串口通讯(转载)

    http://blog.sina.com.cn/s/blog_7880f98301010pi8.html 转自——飘雪的世界 最近两天一直在研究spcomm控件的使用,之前也是很不太明白,看了很多的例 ...

  3. [SQL]分组排练进行更新

    --方法(一):分组排练进行更新 ----------------------------------------------------------------------------------- ...

  4. [SQL]一组数据中Name列相同值的最大Je与最小je的差

    declare @t table(name varchar(),qy varchar(),je int) insert into @t union all union all union all un ...

  5. C Primer Plus(第五版)5

    第5章 运算符,表达式和语句 5.1 循环简单 程序清单 5.1 显示了一个示例程序,该程序做了一点算术运算来计算穿 9 码鞋的脚用英寸表示的长度.为了增加你对循环的理解,程序的第一版演示了不使用循环 ...

  6. (转)Combobox出现System.Data.DataRowView的原因,以及指定ValueMember的时机问题

    原文地址 http://blog.csdn.net/lubiaopan/article/details/5915774 当使用Combobox控件时,出现SelectedValue的值为“System ...

  7. nfs挂在内核出错 T T *** ERROR: Cannot umount

    今天在U-boot挂载nfs内核是出现如下错误,网上查了解决方案. SOCFPGA_CYCLONE5 # nfs 20000 192.168.0.75:/work/nfs_root/uImageWai ...

  8. 在线重定义(Rdefine Table online)

    二.        概念理解 在线重定义用于对表的逻辑或者物理结构的修改,而且在修改时不影响表的可用性与传统方式相比.当一个表被重定义时,会被锁定为exclusive mode很短一段时间,这段时间的 ...

  9. ORA-00245: control file backup failed; target is likely on a local file system (转载)

    环境:DB VERSION: 11.2.0.4.0RAC 2 nodes 问题:邮件显示rman备份失败,查看rman备份日志 Starting Control File and SPFILE Aut ...

  10. linux包转发开发

    28号晚上接到这个任务的, 看了点epoll, 29号上午安装Ubuntu 12.10的G++, 开始把内网的vm虚拟机文件, 复制到外网, 重新建立一个虚拟机再更新, 最后外网也没能安装得了g++. ...