MVC5 Identity 自定义用户和角色
看代码基本就都能看懂了,增加了两个用户详细信息的表,角色表增加两个字段页面中实现树形显示。
//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 自定义用户和角色的更多相关文章
- asp.net core系列 47 Identity 自定义用户数据
一.概述 接着上篇的WebAppIdentityDemo项目,将自定义用户数据添加到Identity DB,自定义扩展的用户数据类应继承IdentityUser类, 文件名为Areas / Ident ...
- .NET 实现自定义ContextUser的Identity和Principal实现自定义用户信息,权限验证。
备用收藏,http://blog.csdn.net/msdnxgh/article/details/6894885 .NET 实现自定义ContextUser的Identity和Principal 在 ...
- SpringSecurity 自定义用户 角色 资源权限控制
SpringSecurity 自定义用户 角色 资源权限控制 package com.joyen.learning.security; import java.sql.ResultSet; impor ...
- Identity角色管理五(添加用户到角色组)
因需要在用户列表中点详情按钮来到当前页,所以需要展示分组详情,并展示当前所属角色组的用户 public async Task<ActionResult> Details(string id ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(27)-权限管理系统-分配用户给角色
系列目录 分配用户给角色,跟分配角色给用户操作是基本一致的. 打开模块维护,展开SysRole模块添加一个操作码,并赋予权限 设置好之后将权限授权给管理员,在SysRole的index添加操作码与js ...
- 基于FormsAuthentication的用户、角色身份认证
一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到 Session中存储的用户基本信息,查看比较他有没有登录和能否 ...
- MVC5+EF6 --自定义控制Action访问权限
本章主要讲解在MVC中灵活控制Action的访问权限: 本章所使用的示例表也是上一张所使用的TbUser.TbRole.TbUserRole: 最终的效果是针对任意一个Action或Controlle ...
- 基于FormsAuthentication的用户、角色身份认证(转)
一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到 Session中存储的用户基本信息,查看比较他有没有登录和能否 ...
- ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core
前言 原本本节内容是不存在的,出于有几个人问到了我:我想使用ASP.NET Core Identity,但是我又不想使用默认生成的数据库表,想自定义一套,我想要使用ASP.NE Core Identi ...
随机推荐
- struts (三)
1. <action name="test" class="com.gc.Test"> <result name="success& ...
- java socket通讯(一) 入门示例
一.入门 要想学习socket通讯,首先得知道tcp/ip和udp连接,具体可参考浅谈TCP/IP 和 UDP的区别 二.示例 首先新建了一个java工程,包括两个部分,客户端SocketClient ...
- ubuntu 14.10 安装 zabbix
在ubuntu 14.10 上部署 zabbix 2.x 基本软件包安装 既然是ubuntu系统,当然要用好apt-get神器. 参考教程 URL:http://blog.csdn.net/cloud ...
- Go Mobile 例子 audio 源码分析
看这个源码分析前,建议先看更简单地例子 basic 的源码分析(http://www.cnblogs.com/ghj1976/p/5183199.html), 一些基础知识本篇将不再提及. audio ...
- [SQL]循环插入数据,并且计算插入所用时间
--得出以上速度的方法是:在各个select语句前加: declare @d datetime set @d=getdate() select * from tb --并在select语句后加: se ...
- [ZOJ 1010] Area (计算几何)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 题目大意:给你n个点,问你顺次连线能否连成多边形?如果能, ...
- OC基础(12)
new方法实现原理 类的本质 类的启动过程 *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bo ...
- Java中1000==1000为false而100==100为true
public static void main(String[] args) { int z1 = 0; int z2 = 0; System.out.println(z1==z2);//TRUE I ...
- 【转】一个URL编码和解码的C++类
下面的代码实现了一个用于C++中转码的类strCoding.里面有UTF8.UNICODE.GB2312编码的互相转换. .H文件: #pragma once #include <iostrea ...
- 【LeetCode】84. Largest Rectangle in Histogram
Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...