Asp. Net MVC anti-forgery token: nameidentifier or identityprovider not present,

Source: Internet
Author: User

Asp. Net MVC anti-forgery token: nameidentifier or identityprovider not present,

When ClaimsIdentity is used, Asp. Net MVC uses the value of ClaimsType (http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier) and IdentityProvider (http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider) in User. Identity by default when generating AntiForgeryToken ). If the STS (Security Token Service) We use does not provide two types of ClaimsType values, then MVC will report an error of generation failure of AntiForgeryToken.

The detailed error message is as follows:

 

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.

From the error message, we can see that Asp.net MVC forces to provide the NameIdentifier and IdentityProvider values, which is the default action. However, this default behavior can be changed. We use ADFS and IdentityProvider. According to the last prompt of the error message, you can modify the value of AntiForgeryConfig. UniqueClaimTypeIdentifier to tell Asp. Net MVC to generate an AntiForgeryToken using another ClaimsType value. For example, to use NameIdentifier, you only need to add the following sentence to Global. asax. cs:

AntiForgeryConfig. UniqueClaimTypeIdentifier = System. Security. Claims. ClaimTypes. NameIdentifier;

After re-compilation, as long as ADFS provides the NameIdentifier program, no error will be reported.

References:
  • Anti-forgery token issue (MVC 5)
  • MVC 4, AntiForgeryToken and Claims

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.