Claims Identity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SecurityDemo
{
class Program
{
static void Main(string[] args)
{
Setup();
CheckCompatibility();
CheckNewClaimsUsage();
Console.ReadLine();
}
private static void Setup()
{
IList<Claim> claimCollection = new List<Claim>
{
new Claim(ClaimTypes.Name, "Andras")
, new Claim(ClaimTypes.Country, "Sweden")
, new Claim(ClaimTypes.Gender, "M")
, new Claim(ClaimTypes.Surname, "Nemes")
, new Claim(ClaimTypes.Email, "hello@me.com")
, new Claim(ClaimTypes.Role, "IT")
};
ClaimsIdentity claimsIdentity =new ClaimsIdentity(claimCollection, "My e-commerce website");
Console.WriteLine(claimsIdentity.IsAuthenticated);
ClaimsPrincipal principal = new ClaimsPrincipal(claimsIdentity);
Thread.CurrentPrincipal = principal;
}
private static void CheckCompatibility()
{
IPrincipal currentPrincipal = Thread.CurrentPrincipal;
Console.WriteLine(currentPrincipal.Identity.Name);
}
private static void CheckNewClaimsUsage()
{
ClaimsPrincipal currentClaimsPrincipal = ClaimsPrincipal.Current;//Thread.CurrentPrincipal as ClaimsPrincipal;
Claim nameClaim = currentClaimsPrincipal.FindFirst(ClaimTypes.Name);
Console.WriteLine(nameClaim.Value);
foreach (ClaimsIdentity ci in currentClaimsPrincipal.Identities)
{
Console.WriteLine(ci.Name);
}
}
}
}
Claims Identity的更多相关文章
- 全新的membership框架Asp.net Identity(2)——绕不过的Claims
本来想直接就开始介绍Identity的部分,奈何自己挖坑太深,高举高打的方法不行.只能自己默默下载了Katana的源代码研究了好一段时间.发现要想能够理解好用好Identity, Claims是一个绕 ...
- Identity Server 4 - Hybrid Flow - Claims
前一篇 Identity Server 4 - Hybrid Flow - MVC客户端身份验证: https://www.cnblogs.com/cgzl/p/9253667.html Claims ...
- AspNet Identity 和 Owin 谁是谁
英文原文:http://tech.trailmax.info/2014/08/aspnet-identity-and-owin-who-is-who/ 最近我发现Stackoverflow上有一个非常 ...
- 译:Asp.Net Identity与Owin,到底谁是谁?
送给正在学习Asp.Net Identity的你 :-) 原文出自 trailmax 的博客AspNet Identity and Owin. Who is who. Recently I have ...
- Identity Server 4 - Hybrid Flow - MVC客户端身份验证
预备知识 可能需要看一点点预备知识 OAuth 2.0 不完全简介: https://www.cnblogs.com/cgzl/p/9221488.html OpenID Connect 不完全简介: ...
- Web API2 使用默认Identity
当您选择个人账户在Web API项目模板,项目包含一个令牌授权服务器验证用户凭证和问题.下面的图显示了相同的凭证流的Web API组件. 发送一个未经授权的请求 首先,运行应用程序并单击按钮调用的AP ...
- 【译】Asp.Net Identity与Owin,到底谁是谁?
送给正在学习Asp.Net Identity的你 :-) 原文出自 trailmax 的博客AspNet Identity and Owin. Who is who. Recently I have ...
- SharePoint Adventures : Using Claims with Reporting Services
Cannot convert claims identity to a windows token. This may be due to user not logging in using win ...
- DotNet 资源大全中文版(Awesome最新版)
Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...
随机推荐
- ArcMap中,如何查看当前工具是否在执行?如何将工具调到前台来执行?
ArcMap中,如何查看当前工具是否在执行?如何将工具调到前台来执行? 描述 如何查看当前工具是否在执行?如何将工具调到前台来执行? 解决办法 后台GP执行中,可以在 Geoprocessing菜单中 ...
- linq查询结果datetime类型转string类型
var list = new SupplierLogic().GetSupplier(pageSize, pageIndex).Select(q => new { SupplierID = q. ...
- 遍历echsop的region表形成缓存的程序
header("Content-type: text/html; charset=utf-8"); $con = mysql_connect("localhost&quo ...
- PHP 判断客户端是IOS还是Android
<?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad ...
- 转: Linux磁盘扩容
from:https://www.rootusers.com/how-to-increase-the-size-of-a-linux-lvm-by-expanding-the-virtual-mach ...
- 关于preg_match输出多个数组的解释,使用()时
第一个数组显示的是所有的匹配,第二个显示的是第一个括号里的内容,第三个显示的是第二个括号里的内容
- 英文不好也能快速"记忆" API
英文不好不要紧,把API函数导入打字练习类软件,即是练习打字速度,提高编程效率:也能短时间记忆API. 坚持每天打一遍,约2小时,连续打两周,会对API有很好的记忆,此方法是结合英文学习方法!以下是W ...
- Android -- 自定义View小Demo,动态画圆(一)
1,转载:(http://blog.csdn.NET/lmj623565791/article/details/24500107),现在如下图的效果: 由上面的效果图可以看到其实是一个在一个圆上换不同 ...
- 重构wangEditor(web富文本编辑器),欢迎指正!
提示:最新版wangEditor请参见:wangEditor.github.io 或者 https://github.com/wangfupeng1988/wangEditor 1. 前言 (下载源码 ...
- Angularjs 中文版API v1.3.9 阅读
http://www.angularjsapi.cn/#/bootstrap 2016.7.4 ng.function: 1.angular.bind(self,fn,args ); 2.angula ...