mvc core2.1 Identity.EntityFramework Core 用户Claims查看(七)
添加角色属性查看
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查看(七)的更多相关文章
- mvc core2.1 Identity.EntityFramework Core 用户列表预览 删除 修改 (五)
用户列表预览 Controllers->AccountController.cs [HttpGet] public IActionResult Index() { return View(_us ...
- mvc core2.1 Identity.EntityFramework Core ROle和用户绑定查看 (八)完成
添加角色属性查看 Views ->Shared->_Layout.cshtml <div class="navbar-collapse collapse"> ...
- mvc core2.1 Identity.EntityFramework Core 配置 (一)
https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/customize_identity_model?view=a ...
- mvc core2.1 Identity.EntityFramework Core 实例配置 (四)
https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/customize_identity_model?view=a ...
- mvc core2.1 Identity.EntityFramework Core 注册 (二)
Startup.cs-> Configure app.UseAuthentication(); //启动验证 Controllers->AccountController.cs 新建 us ...
- mvc core2.1 Identity.EntityFramework Core 导航状态栏(六)
之前做的无法 登录退出,和状态,加入主页导航栏 Views ->Shared->_Layout.cshtml <div class="navbar-collapse col ...
- mvc core2.1 Identity.EntityFramework Core 登录 (三)
Controllers->AccountController.cs 新建 [HttpGet] [AllowAnonymous] public async Task<IActionResul ...
- webapi core2.1 Identity.EntityFramework Core进行配置和操作数据 (一)没什么用
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&am ...
- webapi core2.1 IdentityServer4.EntityFramework Core进行配置和操作数据
https://identityserver4.readthedocs.io/en/release/quickstarts/8_entity_framework.html 此连接的实践 vscode ...
随机推荐
- python中字典常用的方法
#定义一个空字典: a={ } 定义一个字典: d={'age':18} #增加一个元素: d['age']=20 d[k]=v d.setdefault('age',18) d.setde ...
- angular4-注入服务
//配置已创建的服务:import { MemberService } from "./member.service";@NgModule({ // ... providers: ...
- 四:(之五)Dockerfile语法梳理和实践
*5.Dockerfile语法梳理和实践 5.1 尽量使用官方的image作为base image 5.2 metadata:指明作者 版本 描述 5.3 每一条run都能形成一个分层,避免无用分层应 ...
- ORM版学员管理系统1
ORM版学员管理系统 班级表 表结构 class Class(models.Model): id = models.AutoField(primary_key=True) # 主键 cname = m ...
- Cracking The Coding Interview 3.5
//Implement a MyQueue class which implements a queue using two stacks. #include <iostream> #in ...
- jdk8-Optional类
概念: package com.atguigu.java8; import java.util.Optional; import org.junit.Test; /* * 一.Optional 容器类 ...
- 3.10 C++虚基类 虚继承
参考:http://www.weixueyuan.net/view/6367.html 总结: 本例即为典型的菱形继承结构,类A中的成员变量及成员函数继承到类D中均会产生两份,这样的命名冲突非常的棘手 ...
- Java 将图片转成base64,传到前台展示
后台代码: public String getBase64(SysFile sysFile){ String imgStr = ""; try { File file = new ...
- linux Bash 常用
linux 帮助文档 man + [命令] eg: man ls[命令] + --help eg:ls --helphelp +[命令] eg:help ceinfo + [命令] eg:info l ...
- Problem A: 平面上的点——Point类 (I)
Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...