Asp.Net MVC anti-forgery token的问题:nameidentifier or identityprovider not present
当使用ClaimsIdentity的时候,Asp.Net MVC在生成AntiForgeryToken的时候会默认使用User.Identity中两种ClaimsType的值:NameIdentifier (http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier )和IdentityProvider (http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider)。如果我们使用的STS(Security Token Service)没有提供两种ClaimsType的值,那么MVC就会报AntiForgeryToken生成失败的错误。
详细的错误信息是这样的:
A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider' was not present on the provided ClaimsIdentity. To enable anti-forgery token support with claims-based authentication, please verify that the configured claims provider is providing both of these claims on the ClaimsIdentity instances it generates. If the configured claims provider instead uses a different claim type as a unique identifier, it can be configured by setting the static property AntiForgeryConfig.UniqueClaimTypeIdentifier.
从错误提示我们可以看到Asp.net MVC强制要求提供NameIdentifier和IdentityProvider这两个值,这是默认的行为。但是这个默认的行为是可以改的。我们用ADFS,IdentityProvider这个值是没有的。根据错误消息的最后一句提示我们,可以修改AntiForgeryConfig.UniqueClaimTypeIdentifier的值,从而告诉Asp.Net MVC用别的ClaimsType的值来生成AntiForgeryToken。比如我们准备使用NameIdentifier,只需要在Global.asax.cs中添加下面一句话:
AntiForgeryConfig.UniqueClaimTypeIdentifier = System.Security.Claims.ClaimTypes.NameIdentifier;
重新编译运作之后,只要ADFS提供了NameIdentifier程序就不会再报错了。
参考资料:
Asp.Net MVC anti-forgery token的问题:nameidentifier or identityprovider not present的更多相关文章
- asp.net MVC中防止跨站请求攻击(CSRF)的ajax用法
参考: Preventing Cross-Site Request Forgery (CSRF) AttacksValidating .NET MVC 4 anti forgery tokens in ...
- Asp.net MVC 3 防止 Cross-Site Request Forgery (CSRF)原理及扩展 安全 注入
原理:http://blog.csdn.net/cpytiger/article/details/8781457 原文地址:http://www.cnblogs.com/wintersun/archi ...
- ABP Zero示例项目登录报错“Empty or invalid anti forgery header token.”问题解决
ABP Zero项目,登录时出现如图"Empty or invalid anti forgery header token."错误提示的解决方法: 在 WebModule.cs的P ...
- asp.net mvc 微信公众号token验证
本人的公众号要申请成为开发者,必须经过token认证.微信公众号的官方代码只列出了PHP代码的实例,明显是歧视.net用户.我用的asp.net mvc中的web api,结果调了好久都没有成功,最后 ...
- ASP.NET MVC中防止跨站请求攻击(CSRF)
转载 http://kevintsengtw.blogspot.co.nz/2013/01/aspnet-mvc-validateantiforgerytoken.html 在 ASP.NET M ...
- 认识ASP.NET MVC的5种AuthorizationFilter
在总体介绍了筛选器及其提供机制(<深入探讨ASP.NET MVC的筛选器>)之后,我们按照执行的先后顺序对四种不同的筛选器进行单独介绍,首先来介绍最先执行的AuthorizationFil ...
- Anti-Forgery Request Recipes For ASP.NET MVC And AJAX
Background (Normal scenario of form submitting) To secure websites from cross-site request forgery ( ...
- ASP.NET MVC Ajax 伪造请求
1.前言 CSRF(Cross-site request forgery)跨站请求伪造,ASP.NET MVC 应用通过使用AJAX请求来提升用户体验,浏览器开发者工具可以一览众山小,就很容易伪造了请 ...
- ASP.NET MVC 防止CSRF攻击
简介 MVC中的Html.AntiForgeryToken()是用来防止跨站请求伪造(CSRF:Cross-site request forgery)攻击的一个措施,它跟XSS(XSS又叫CSS:Cr ...
随机推荐
- 【转载】表单验证<AngularJs>
原文地址:http://www.cnblogs.com/rohelm/archive/2014/10/19/4033513.html 常用的表单验证指令 1. 必填项验证 某个表单输入是否已填写,只要 ...
- C语言基础(15)-多文件编译
一.头文件的使用 如果把main函数放在第一个文件中,而把自定义函数放在第二个文件中,那么就需要在第一个文件中声明函数原型.如果把函数原型包含在一个头文件里,那么就不必每次使用函数的时候都声明其原型了 ...
- 142. Linked List Cycle II【easy】
142. Linked List Cycle II[easy] Given a linked list, return the node where the cycle begins. If ther ...
- 40-语言入门-40-C小加之随机数
题目地址: http://acm.nyist.net/JudgeOnline/problem.php?pid=255 15 20 32 40 67 89 300 400 代码: #includ ...
- Editing a Book UVA - 11212 IDA*
You have n equal-length paragraphs numbered 1 to n . Now you want to arrange them in the order of 1 ...
- HTML5之本地存储localstorage
Web Storage是HTML5引入的一个非常重要的功能,可以在客户端本地存储数据,类似HTML4的cookie,但可实现功能要比cookie强大的多,cookie大小被限制在4KB,Web Sto ...
- HashMap与HashTable原理及数据结构
HashMap与HashTable原理及数据结构 hash表结构个人理解 hash表结构,以计算出的hashcode或者在hashcode基础上加工一个hash值,再通过一个散列算法 获取到对应的数组 ...
- HTML5实现端访问时禁止放大和缩小网页
<title>html5禁止和移动.缩放网页</title><meta name="viewport" content="width=dev ...
- python 装饰器 (多个参数的函数,带参数的装饰器)
最简单的模板是这样的 #-*-coding:utf-8-*- def outer(func): def inner(): print 'before' func() print 'after' # r ...
- 模式识别之概率分布---平均分布,正态分布,一阶滑动和,一阶线性回归 C语言编程
http://wenku.baidu.com/view/11cb1669a98271fe910ef9c6.html