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

//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. Java中的JDBC基础

    简介 JAVA程序想要对数据库进行访问,需要有JDBC驱动程序的支持.JDBC驱动程序提供了对各种主流数据库的接口,程序员只需要学习掌握这一套接口,就可以实现对所有数据库的访问代码编写. 一般步骤 J ...

  2. jQuery 的append在ie下的兼容性

    $("body").append("<div id='ajaxLoadDiv'><span><img src='images/ajaxLoa ...

  3. 关于BEA-000402和BEA-000438

    OS:rh5 64位 JDK:1.5 64位 weblogic:9.2.3 jar 应用程序部署后,启动受管服务器报如下警告和错误: 这个问题导致系统性能下降,打开weblogic控制台各项功能和应用 ...

  4. [SQL]开启事物,当两条插入语句有出现错误的时候,没有错误的就插入到表中,错误的语句不影响到正确的插入语句

    begin transaction mustt insert into student values(,'kkk','j大洒扫','j','djhdjh') insert into student v ...

  5. POJ 3308 Paratroopers(最小割EK(邻接表&矩阵))

    Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...

  6. MongoDB添加用户

    1.添加超级管理员用户 1)切换到admin数据库 >use admin 2)添加管理员用户 >db.addUser("admin","admin" ...

  7. Spring 配置文件详解 http://www.blogjava.net/hellxoul/archive/2011/11/19/364324.html

    1.基本配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http: ...

  8. OC基础(10)

    id类型 SEL类型 *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !im ...

  9. Unity AssetBundles and Resources指引 (三) AssetBundle基础

    本文内容主要翻译自下面这篇文章 https://unity3d.com/cn/learn/tutorials/topics/best-practices/guide-assetbundles-and- ...

  10. rabbitmq学习笔记

    1 基本概念 rabbitmq server(broker server):rabbitmq服务 client:包括producers和consumer message:包括payload和label ...