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