首页 新闻 赞助 找找看

Html.AntiForgeryToken 突然报这个错误 太奇怪了

0
悬赏园豆:10 [已关闭问题] 关闭于 2020-11-12 10:40

Mvc
问题补充:

System.InvalidOperationException
HResult=0x80131509
Message=提供的 ClaimsIdentity 上不存在类型“http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier”或“http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider”的声明。若要使用基于声明的身份验证启用防伪标记支持,请确认配置的声明提供程序在它生成的 ClaimsIdentity 实例上同时提供这两个声明。如果配置的声明提供程序使用其他声明类型作为唯一标识符,则可以通过设置静态属性 AntiForgeryConfig.UniqueClaimTypeIdentifier 来配置该提供程序。
Source=System.Web.WebPages
StackTrace:
在 System.Web.Helpers.AntiXsrf.ClaimUidExtractor.GetUniqueIdentifierParameters(ClaimsIdentity claimsIdentity, String uniqueClaimTypeIdentifier)
在 System.Web.Helpers.AntiXsrf.ClaimUidExtractor.ExtractClaimUid(IIdentity identity)
在 System.Web.Helpers.AntiXsrf.TokenValidator.GenerateFormToken(HttpContextBase httpContext, IIdentity identity, AntiForgeryToken cookieToken)
在 System.Web.Helpers.AntiXsrf.AntiForgeryWorker.GetTokens(HttpContextBase httpContext, AntiForgeryToken oldCookieToken, AntiForgeryToken& newCookieToken, AntiForgeryToken& formToken)
在 System.Web.Helpers.AntiXsrf.AntiForgeryWorker.GetFormInputElement(HttpContextBase httpContext)
在 System.Web.Helpers.AntiForgery.GetHtml()
在 System.Web.Mvc.HtmlHelper.AntiForgeryToken()
在 ASP._Page_Views_Shared__LoginPartial_cshtml.Execute() 在 C:\Users\chent\Source\Repos\DMS\DMSPortal\Views\Shared_LoginPartial.cshtml 中: 第 7 行
在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
在 System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
在 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
在 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
在 System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
在 System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName)
在 ASP._Page_Views_Shared__Layout_cshtml.Execute() 在 C:\Users\chent\Source\Repos\DMS\DMSPortal\Views\Shared_Layout.cshtml 中: 第 38 行
在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
在 System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
在 System.Web.WebPages.WebPageBase.<>c__DisplayClass40_0.<RenderPageCore>b__0(TextWriter writer)
在 System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
在 System.Web.WebPages.WebPageBase.Write(HelperResult result)
在 System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action1 body) 在 System.Web.WebPages.WebPageBase.PopContext() 在 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) 在 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) 在 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) 在 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) 在 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) 在 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
在 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)

_York的主页 _York | 初学一级 | 园豆:3
提问于:2020-11-09 14:31
< >
分享
所有回答(1)
0

AntiForgeryConfig.UniqueClaimTypeIdentifier =“ sub”;
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary();

https://brockallen.com/2012/07/08/mvc-4-antiforgerytoken-and-claims/

_York | 园豆:3 (初学一级) | 2020-11-12 10:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册