首页 新闻 赞助 找找看

@Html.AntiForgeryToken()

0
悬赏园豆:10 [已解决问题] 解决于 2016-11-14 14:23

加上@Html.AntiForgeryToken() 就报这个错误。是什么意思呢。

问题补充:

登录使用了SignManager

挨踢新手的主页 挨踢新手 | 初学一级 | 园豆:71
提问于:2016-11-14 09:41
< >
分享
最佳答案
0

把错误堆栈信息贴上来

收获园豆:10
czd890 | 专家六级 |园豆:14292 | 2016-11-14 11:42

实在不太明白

挨踢新手 | 园豆:71 (初学一级) | 2016-11-14 13:17

@挨踢新手: 

internal static string[] GetUniqueIdentifierParameters(ClaimsIdentity claimsIdentity, string uniqueClaimTypeIdentifier)
        {
            IEnumerable<Claim> claims = claimsIdentity.GetClaims();
            if (!string.IsNullOrEmpty(uniqueClaimTypeIdentifier))
            {
                Claim claim4 = claims.SingleOrDefault((Claim claim) => string.Equals(uniqueClaimTypeIdentifier, claim.ClaimType, StringComparison.Ordinal));
                if (claim4 == null || string.IsNullOrEmpty(claim4.Value))
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, WebPageResources.ClaimUidExtractor_ClaimNotPresent, new object[]
                    {
                        uniqueClaimTypeIdentifier
                    }));
                }
                return new string[]
                {
                    uniqueClaimTypeIdentifier,
                    claim4.Value
                };
            }

claims.SingleOrDefault异常了。

action里面看看是不是有重复的claimtype。

如果你没有修改System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier的化。就看claimtype有没有多个等于string.empty的。

(this.User.Identity as System.Security.Claims.ClaimsIdentity).Claims

czd890 | 园豆:14292 (专家六级) | 2016-11-14 13:46

@calvinK:  十分感谢

Claims.Add(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()))

Claims.Add(new Claim(ClaimTypes.GivenName, user.UserName))

手动添加了这两个Claim导致的。这两个Claim在SignManager中会自动添加

挨踢新手 | 园豆:71 (初学一级) | 2016-11-14 14:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册