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 ...
随机推荐
- [ActionScript 3.0] AS3.0 动态加载显示内容
可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...
- 浅析JAVA_HOME,CLASSPATH和PATH的作用
1,设置JAVA_HOME: java的目录一.为了方便引用,比如,你JDK安装在C:\ProgramFiles\Java\jdk1.7.0目录里,则设置JAVA_HOME为该目录路径, 那么以后你 ...
- 页面设计--RadioButton
RadioButton单选控件支持多分组模式 属性如下图 设计: web显示效果图:
- cctype函数 (字符类型判断)
这些函数都在cctype头文件定义 isalnum(c) 如果C是字母或数字,则为TRUE isalpha(c) 如果C是字母,返回TRUE iscntrl(c) 如果C是控制字符,返回TRUE ...
- (转)C# SSL-X509使用
X.509 给出的鉴别框架是一种基于公开密钥体制的鉴别业务密钥管理.一个用户有两把密钥:一把是用户的专用密钥(简称为:私钥),另一把是其他用户都可得到和利用的公共密钥(简称为:公钥).该鉴别框架允许用 ...
- 403 Forbidden
http://baike.baidu.com/link?url=JJXC_XqJ2d-twe1dhbLUiRgvZU5OfneRURT4LvrtWBqv9Av4J0GPOlwk3KQuRx4Hzu4N ...
- Spark是一种分布式的计算方案
Spark的安装基于HDFS,所以我们要设置hadoop的配置文件,所以spark的存储不是其主要的功能点,而spark作为分布式生态中的角色是一种计算模式(其他 的计算 模式,比如MR,Storm, ...
- PreparedStatement和Statment
使用Statment安全性差,存在SQL注入隐患 public static void main(String[] args) { Connection conn=null; Statement st ...
- eclipse 调试时出现 Error: [Errno 10013]
法1: 端口占用错误.换个端口即可. 新端口 在 8001到15536之间的任意值. 法2: windows下查看哪个程序占用端口 netstat -ano | findstr “8080” 找到p ...
- MFC学习 事件临界区
事件: #include <Windows.h> #include <iostream> DWORD WINAPI Func1Pro(LPVOID lpParameter); ...