Asp.Net MVC anti-forgery token的问题:nameidentifier not present
前一篇关于anti-forgery token问题的博文提到我们可以通过修改AntiForgeryConfig.UniqueClaimTypeIdentifier属性来避免AntiForgeryToken生成的问题。但是也许你编译运行后又得到了这样一个错误:
A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' was not present on the provided ClaimsIdentity.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' was not present on the provided ClaimsIdentity.
Source Error:Line 4: using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
Line 5: {
Line 6: @Html.AntiForgeryToken()
Line 7:
Line 8: <ul class="nav navbar-nav navbar-right">
这说明做身份验证的STS (比如 ADFS)没有提供NameIdentifier的信息。以ADFS为例,什么是NameIdentifier,看图

NameIdentifier在ADFS中就是“Name ID”。这是我的ADFS上配置的一条”Claims Rule“,将Active Directory用户的E-mail地址映射为Claim Based Identity中的Name ID。这里要注意,图中左边的LDAP Attribute必须要有值,否则即使我们配置了一条映射,在用户登陆后ADFS发出的Claims中也没有我们要的数据,比如本例中的Name ID。
如何确定LDAP Attribute也没有值?打开Active Directory的用户属性界面,确认我们需要的属性(比如E-mail)不为空。

如果不清楚后端的STS到底提供了哪些可用的Claims Types,可以在页面添加如下的代码来显示当前所有拿到的身份验证的信息
@if (Request.IsAuthenticated)
{
<ul>
@foreach (var claim in ((System.Security.Claims.ClaimsIdentity)User.Identity).Claims)
{
<li>Issuer:@claim.Issuer OriginalIssuer:@claim.OriginalIssuer Value:@claim.Value</li>
}
</ul>
}

Asp.Net MVC anti-forgery token的问题:nameidentifier 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 anti-forgery token的问题:nameidentifier or identityprovider not present
当使用ClaimsIdentity的时候,Asp.Net MVC在生成AntiForgeryToken的时候会默认使用User.Identity中两种ClaimsType的值:NameIdentifi ...
- 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 ...
随机推荐
- VB的第一个项目
前言-----本人也是刚刚接触VB,企业的VB代码基本能看的懂,但是自己开发,只能呵呵.一般在刚学习一门新的语言时,很容易发生一些自己相当然的认识错误,so,记下并分享开发学习的过程,望指正.--- ...
- TLS
1. SSL简介 SSL(SecureSocket Layer)安全套接层,是网景公司提出的用于保证Server与client之间安全通信的一种协议,该协议位于TCP/IP协议与各应用层协议之间,即S ...
- Yum Error Another app is currently holding the yum lock; waiting for it to exit
Another app is currently holding the yum lock; waiting for it to exit... The other application is: P ...
- Atitit. visual studio vs2003 vs2005 vs2008 VS2010 vs2012 vs2015新特性 新功能.doc
Atitit. visual studio vs2003 vs2005 vs2008 VS2010 vs2012 vs2015新特性 新功能.doc 1.1. Visual Studio2 1.2. ...
- 王立平--Eclipse中配置svn
1.-------------------------------------------------------------------------------------------------- ...
- shell脚本之微信报警功能的实现
导语:现在越来越流行微信报警功能了.下面就来看看具体实现吧! 1.先申请一个微信企业号 传送门:http://work.weixin.qq.com/ 2.添加用户 2.创建应用 3.创建管理组并添加管 ...
- Django学习之URLconf
Django处理request的步骤: 1.确定根URLconf 2.载入urls.py,找到变量urlpatterns,urlpatterns是django.conf.urls.url()的实例对象 ...
- iOS swift 代理协议
swift中的代理实现和oc中是有区别的 protocol HXQLimitedTextFieldDelegate{ func test() } 代理中默认所有方法都是required,如果需要某个代 ...
- SQL : IN 和 Exists 的区别
Sql语句中IN和exists的区别及应用 表展示 首先,查询中涉及到的两个表,一个user和一个order表,具体表的内容如下: user表: order表: in 确定给定的值是否与子查询或列表中 ...
- 一步一步解析H.264码流的NALU(SPS,PSS,IDR)获取宽高和帧率
分析H.264码流的工具 CodecVisa,StreamEye以及VM Analyzer NALU是由NALU头和RBSP数据组成,而RBSP可能是SPS,PPS,Slice或SEI 而且SPS位于 ...