添加角色属性查看

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. thinkphp5多语言

    一.配置 1.'lang_switch_on' => true, 2.'lang_list' => ['zh-cn','en-us',] 二.语言定义() 1.新建文件/en-us.php ...

  2. Win10系列:UWP界面布局进阶6

    在Windows 10的"个性化设置"中,用户可以更改计算机在锁屏状态下的背景图片,除此之外,也可以通过Windows应用商店应用程序将喜欢的图片设置为锁屏背景,下面通过一个示例来 ...

  3. 异常处理机制中的return关键字

    Java中,执行try-catch-finally语句需要注意: 第一:return语句并不是函数的最终出口,如果有finally语句,这在return之后还会执行finally(return的值会暂 ...

  4. Traumland--梦乡--IPA--德语

    德国电影<<英俊少年>>的插曲.

  5. 对称加密-java实现

    主要步骤如下: 1.利用SecretKeyFactory.getInstance("加密算法")创建密钥工厂,加密算法如"DES","AES" ...

  6. activemq 生产消费模式,订阅发布模式不同类型数据传输

    1.项目结构 2. activemq-pom pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...

  7. [Paper] LCS: An Efficient Data Eviction Strategy for Spark

    Abstract Classical strategies do not aware of recovery cost, which could cause system performance de ...

  8. [转] ajax方法

    1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如 ...

  9. 转-Asynchronous bulk transfer using libusb

    https://falsinsoft.blogspot.jp/2015/02/asynchronous-bulk-transfer-using-libusb.html The 'linusb' is ...

  10. Python 数据结构--排序

      各种排序的时间复杂度和空间复杂度   以下 冒泡排序,选择排序,插入排序,合并排序,快速排序,希尔排序   1 冒泡排序(Bubble Sort) 冒泡排序(Bubble Sort)是一种简单的排 ...