the roles of a ClaimsPrincipal are actually just claims create with a type of ClaimsIdentity.RoleClaimType. By default, this is given by ClaimType.Role, which is the string http://schemas.microsoft.com/ws/2008/06/identity/claims. When a user is authenticated appropriate claims are added for their roles which can be found later as required.

It's worth bearing this in mind if you have difficult with AuthorizeAttributes not working. Most external identity providers will use a different set of claims representing role, name etc that do not marry up with the values used by Microsoft in the ClaimType class. As Dominick Baier discusses on his blog, this can lead to situations where claims are not translated and so users can appear to not be in a given role. If you run into issues where your authorisation does not appear to working correctly, I strongly recommend you check out his post for all the details.

http://andrewlock.net/introduction-to-authorisation-in-asp-net-core/

https://leastprivilege.com/2016/08/21/why-does-my-authorize-attribute-not-work/

Why does my Authorize Attribute not work?的更多相关文章

  1. ASP.NET MVC自定义验证Authorize Attribute

    前几天Insus.NET有在数据库实现过对某一字段进行加密码与解密<使用EncryptByPassPhrase和DecryptByPassPhrase对MS SQLServer某一字段时行加密和 ...

  2. ASP.NET MVC自定义验证Authorize Attribute(包含cookie helper)

    前几天Insus.NET有在数据库实现过对某一字段进行加密码与解密<使用EncryptByPassPhrase和DecryptByPassPhrase对MS SQLServer某一字段时行加密和 ...

  3. ASP.NET Core MVC 授权的扩展:自定义 Authorize Attribute 和 IApplicationModelProvide

    一.概述 ASP.NET Core MVC 提供了基于角色( Role ).声明( Chaim ) 和策略 ( Policy ) 等的授权方式.在实际应用中,可能采用部门( Department , ...

  4. jquery.uploadify不支持MVC的Authorize

    原文发布时间为:2011-10-18 -- 来源于本人的百度文章 [由搬家工具导入] 为什么jquery.uploadify不支持MVC的Authorize呢,因为flash的cookie跟服务端的不 ...

  5. [转]ASP.NET Core--根据方案来限制身份

    本文转自:http://www.cnblogs.com/duyao/p/5980105.html 翻译如下: 在某些情况下,比如单页的应用程序,可以与多种认证来方式结合.例如,您的应用程序可能使用基于 ...

  6. [转]Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)

    本文转自:https://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-o ...

  7. [转]How do you create a custom AuthorizeAttribute in ASP.NET Core?

    问: I'm trying to make a custom authorization attribute in ASP.NET Core. In previous versions it was ...

  8. ASP.NET Core--根据方案来限制身份

    翻译如下: 在某些情况下,比如单页的应用程序,可以与多种认证来方式结合.例如,您的应用程序可能使用基于Cookie的身份验证来登录和JavaScript的请求承载认证.在某些情况下,可能一个授权验证的 ...

  9. 关于如何使用Identity的文献

    有几篇文件,深入浅出地讲解了如何一步一步的使用Identity,感觉十分有用,留下链接,备查. 1. Configuring Db Connection and Code-First Migratio ...

随机推荐

  1. eclipse怎么在项目里面批量替换单词

    先选中你要替换的东东,然后再菜单栏中找到Search→Text→Project(先创建要搜索的project),这样就会在整个项目中查找单词.然后在Search的Console中,单击项目,右键选择R ...

  2. List<Map> 排序

    import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.u ...

  3. php写入、追加写入文件的实例

    $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); $t ...

  4. webservice有关application/xop+xml的异常

    今天同事调用一个webservice时返回类似错误 响应消息的内容类型 multipart/related; type="application/xop+xml"; boundar ...

  5. 乘积最大(线性dp)

    乘积最大 时间限制: 1 Sec  内存限制: 128 MB提交: 4  解决: 4[提交][状态][讨论版][命题人:quanxing] 题目描述 今年是国际数学联盟确定的“2000——世界数学年” ...

  6. 1097 Deduplication on a Linked List

    题意: 给出一个链表,删除绝对值相同的结点,对于每个绝对值为K的结点,只保留第一次出现的那个.把被移除的结点组成一个新链表,输出删除去重后的链表和新链表. 思路:考察链表的“删除”操作,不难. 代码: ...

  7. Invalid byte tag in constant pool: 19

    环境: windows 2008 server R2   ; tomcat 8.5.3 ;   jdk-1.8.0_91 故障截图: 报的就是 Invalid byte tag in constant ...

  8. 三个线程打印ABC10次,ABCABCABC....

    // ConsoleApplication2.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream&g ...

  9. git学习3 - 克隆远程库到本地 将本地库上传到git

    如何克隆远程版本库到本地 git clone URL 如何用命令将本地项目上传到git 1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 (注意: cd C:/U ...

  10. Kali下Ahmyth的使用

    项目地址:https://github.com/AhMyth/AhMyth-Android-RAT 下载后打开 安装nodejs,nodejs在官网下载,下载完后解压,切到bin目录下 设置全局 ro ...