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

Source: Internet
Author: User

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

In the previous post about the anti-forgery token issue, we mentioned that we can modify the AntiForgeryConfig. UniqueClaimTypeIdentifier attribute to avoid generation of AntiForgeryToken. However, you may get another error after compiling and running:

 

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">

This indicates that the STS for identity authentication (such as ADFS) does not provide NameIdentifier information. Take ADFS as an example. What is NameIdentifier?

NameIdentifier is "Name ID" in ADFS ". This is a Claims Rule configured on my ADFS. It maps the E-mail address of an Active Directory user to the Name ID in Claim Based Identity. Here you wantNote: The LDAP Attribute on the left must have a value. Otherwise, even if a ing is configured, the Claims issued by ADFS does not have the data we want after the user logs in.For example, Name ID in this example.

How can I determine whether LDAP Attribute has no value? Open the user properties interface of Active Directory and confirm that the required properties (such as E-mail) are not empty.

If you do not know the available Claims Types provided by the backend STS, you can add the following code on the page to display all the authentication information currently obtained.

 

    @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>
    }

 

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.