添加角色属性查看

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. Ie11 的改变

    摘录地址:     http://www.4fang.net/content.jsp?id=30537 微软在上周刚刚发布了用于Windows 8.1上的首个Internet Explorer 11的 ...

  2. Uva 10635 - Prince and Princess 问题转化,元素互不相同(在自身序列中独特)的两个数列的LCS,LIS 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. It is never too late!

    整理着过去的学习笔记,零零碎碎的,偶尔夹杂着当时的心境. 泛泛的学着东西,不很系统,不很深入,倒像是在拾海,有时捡捡贝壳,有时抓抓螃蟹.叹服大海的神奇,还没来得及深钻某个领域. (以下内容写于2016 ...

  4. vue-8-组件

    注册 注册一个全局组件:Vue.component(tagName, options) Vue.component('my-component', { template: '<div>A ...

  5. Android : 代码多维度管理(产品风味) - flavorDimensions & productFlavors

    一.关于配置产品风味 Android studio 升级到3.0之后,gradle增加了多维度管理配置,便于同一个项目中创建应用的不同版本,分别管理依赖项并签署配置.创建产品风味与创建构建类型类似:只 ...

  6. mongoose的笔记

    本文地址转载自:http://www.cnblogs.com/egger/archive/2013/06/14/3135847.html  本文将介绍操作符的使用,配合操作符,我们可以执行更加复杂的操 ...

  7. SAL-9 获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'

    题目描述 获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'CREATE TABLE `dept_man ...

  8. 数控AGC实现(转)

    相关链接:    一种混合式高动态范围AGC算法与FPGA实现     http://www.sohu.com/a/221438387_781333 基于FPGA的快速自动增益控制系统设计      ...

  9. VCL界面控件DevExpress VCL Controls发布v18.2.4|附下载

    DevExpress VCL Controls是 Devexpress公司旗下最老牌的用户界面套包.所包含的控件有:数据录入,图表,数据分析,导航,布局,网格,日程管理,样式,打印和工作流等,让您快速 ...

  10. 网站如何实现 在qq中发自己链接时,便自动获取链接标题、图片和部分内容

    如何实现像这种效果?答案如下(要采用分享的形式,复制链接有可能会实现不了效果,至少我的测试是这样的) <head>标签内有QQ专有的标签可以控制要注意QQ的缓存机制,对同一个链接,修改后可 ...