添加角色属性查看

Views ->Shared->_Layout.cshtml


<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
  <li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
  <li><a asp-area="" asp-controller="Home" asp-action="About">About</a></li>
  <li><a asp-area="" asp-controller="Home" asp-action="Contact">Contact</a></li>
  <li><a asp-area="" asp-controller="Account" asp-action="Index">Account</a></li>
  <li><a asp-area="" asp-controller="Claims" asp-action="Index">Claims</a></li>   //加这句

Controllers->ClaimsController.cs 新建

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using IdentityMvc.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authorization;
using IdentityMvc.Models.AccountViewModels;
using Microsoft.AspNetCore.Authentication;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using System.Security.Claims; namespace IdentityMvc.Controllers
{
public class ClaimsController : Controller
{ [Authorize]
public ActionResult Index() {
ClaimsIdentity ident = HttpContext.User.Identity as ClaimsIdentity;
if (ident == null) {
return View("Error", new string[] { "No claims available" });
} else {
return View(ident.Claims);
}
}
}
}

Views->Claims->Index.cshtml 新建

@using System.Security.Claims
@using IdentityMvc.App_Code
@model IEnumerable<Claim>
@{ ViewBag.Title = "Claims"; } <div class="panel panel-primary">
<div class="panel-heading">
Claims
</div>
<table class="table table-striped">
<tr>
<th>Subject</th><th>Issuer</th>
<th>Type</th><th>Value</th>
</tr>
@foreach (Claim claim in Model.OrderBy(x => x.Type)) {
<tr>
<td>@claim.Subject.Name</td>
<td>@claim.Issuer</td>
<td>
@{
IdentityHelpers dd= new IdentityHelpers();
@Html.Raw( dd.ClaimType(@claim.Type));
}
</td>
<td>@claim.Value</td>
</tr>
}
</table>
</div>

App_Code->IdentityHelpers.cs 新建

using System;
using System.Linq;
using System.Reflection;
using System.Security.Claims; namespace IdentityMvc.App_Code
{ public class IdentityHelpers { public string ClaimType( string claimType) { return string.Format("{0}", claimType.Split('/', '.').Last());
} }
}

mvc core2.1 Identity.EntityFramework Core 用户Claims查看(七)的更多相关文章

  1. mvc core2.1 Identity.EntityFramework Core 用户列表预览 删除 修改 (五)

    用户列表预览 Controllers->AccountController.cs [HttpGet] public IActionResult Index() { return View(_us ...

  2. mvc core2.1 Identity.EntityFramework Core ROle和用户绑定查看 (八)完成

    添加角色属性查看 Views ->Shared->_Layout.cshtml <div class="navbar-collapse collapse"> ...

  3. mvc core2.1 Identity.EntityFramework Core 配置 (一)

    https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/customize_identity_model?view=a ...

  4. mvc core2.1 Identity.EntityFramework Core 实例配置 (四)

    https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/customize_identity_model?view=a ...

  5. mvc core2.1 Identity.EntityFramework Core 注册 (二)

    Startup.cs-> Configure app.UseAuthentication(); //启动验证 Controllers->AccountController.cs 新建 us ...

  6. mvc core2.1 Identity.EntityFramework Core 导航状态栏(六)

    之前做的无法 登录退出,和状态,加入主页导航栏 Views ->Shared->_Layout.cshtml <div class="navbar-collapse col ...

  7. mvc core2.1 Identity.EntityFramework Core 登录 (三)

    Controllers->AccountController.cs 新建 [HttpGet] [AllowAnonymous] public async Task<IActionResul ...

  8. webapi core2.1 Identity.EntityFramework Core进行配置和操作数据 (一)没什么用

    https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&am ...

  9. webapi core2.1 IdentityServer4.EntityFramework Core进行配置和操作数据

    https://identityserver4.readthedocs.io/en/release/quickstarts/8_entity_framework.html 此连接的实践 vscode ...

随机推荐

  1. java倒计时使用java.util.Timer实现,使用两个线程,以秒为单位

    public class Countdown3 { private int lin; private int curSec; public Countdown3(int lin)throws Inte ...

  2. java的八大排序

    public class Sort2 { public static void main(String[] args) { Sort2 sort = new Sort2(); System.out.p ...

  3. 在docker hub,用github的dockerfile自动生成docker镜像

    简介: 我已经深深的爱上了docker技术. 在日常使用中,经常看到docker hub 中有很多autobuild的镜像.基本使用是在github中上传dockerfile,过一会儿,docker ...

  4. bind配置文件

    options{} - 整个bind使用的全局配置选项 bind监听的端口,数据文件存储位置,缓存的存储位置,权限加密的控制 logging{}- 服务日志选项 日志输出的位置,以及输出的级别 zon ...

  5. python中的循环以及,continue和break的使用

    循环 目标 程序的三大流程 while 循环基本使用 break 和 continue while 循环嵌套 01. 程序的三大流程 在程序开发中,一共有三种流程方式: 顺序 —— 从上向下,顺序执行 ...

  6. L258 技术转让

    We will inform you of the weight, measurements, number of cases, cost of the drawings and other docu ...

  7. Python socketserver ftp功能简单讲解

    socketserver模块实现并发 为什么要讲socketserver?我们之前写的tcp协议的socket是不是一次只能和一个客户端通信,如果用socketserver可以实现和多个客户端通信.它 ...

  8. SQL注入之Sqli-labs系列第十五关和第十六关(基于POST的时间盲注)

    开始挑战第十五关(Blind- Boolian Based- String)和 第十六关(Blind- Time Based- Double quotes- String) 访问地址,输入报错语句 ' ...

  9. python 模块基础 和常用的模块

    模块的定义 一个模块就是以.py结尾的python 文件,用来从逻辑上组织python代码.注意,模块名和变量名一样开头不能用数字,可以是双下划线和字母. 为什么要用模块? 将一些复杂的需要重复使用的 ...

  10. 如何使用DAX函数解决动态图表标题

    您可能知道,Power BI中的图表(以及许多其他可视化)具有可以设置为任何静态文本的标题.您可以通过选择图表,转到“可视化对象”窗格中的“格式”选项卡,然后更改“标题”部分中的属性(如下所示)来完成 ...