首页 > 数据库技术 > 详细

MVC5 A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 'http://schemas.microsoft.com/accesscontrolservice/2

时间:2014-09-02 19:45:15      阅读:425      评论:0      收藏:0      [点我收藏+]

前台页面使用@Html.AntiForgeryToken()和Controller中的[ValidateAntiForgeryToken]配合使用可以防止CSRF攻击,详细介绍可查看一下链接:

http://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html

 

出现当前错误,是因为在登陆完成为当前用户创建ClaimsIdentity对象时没有指定ClaimTypes,导致验证时不知道该用什么类型进行验证,或者验证类型不正确。

 

解决办法:

打开Global.asax文件,在 Application_Start()方法中添加

AntiForgeryConfig.UniqueClaimTypeIdentifier =ClaimTypes.Name;

如果不知道到底该配置为什么类型,防止配置错误,可以用如下方式查看类型:

1.先将前台页面的@Html.AntiForgeryToken()删除掉,在Controller中添加如下代码

   string strCurrentType = AntiForgeryConfig.UniqueClaimTypeIdentifier;

2.在上面那句代码上打断点,然后调试项目,就能知道在Application_Start()方法中究竟该配置哪个类型了。

MVC5 A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 'http://schemas.microsoft.com/accesscontrolservice/2

原文:http://www.cnblogs.com/pkwblack/p/3952111.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!