Reputation: 1775
Moving away from Forms Authentication and trying to get my head around Claims Identity users can successfully login using this
Dim vIdentity As New ClaimsIdentity({New Claim(ClaimTypes.Name, Session("UserName"))}, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role)
vIdentity.AddClaim(New Claim(ClaimTypes.Role, "User"))
Authentication.SignIn(New AuthenticationProperties With {.IsPersistent = False}, vIdentity)
But having problems with the logout - I thought AuthenticationManager.Signout() would work but I get 'Signout is not a member of AuthenticationManager' so now a little stumped.
This is in Global
System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier = System.Security.Claims.ClaimTypes.Name
I tried this in the logout controller
Function Index() As ActionResult
If User.Identity.IsAuthenticated Then
Dim vUser = TryCast(User, ClaimsPrincipal)
Dim vIdentity = TryCast(User.Identity, ClaimsIdentity)
Dim vClaim = (From c In vUser.Claims Where c.Value = Session("UserName") Select c).Single()
vIdentity.RemoveClaim(vClaim)
End If
Return View()
End Function
But that returned the error
A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name' was not present on the provided ClaimsIdentity.
when it hit
@Html.AntiForgeryToken()
Any ideas?
Thanks
Upvotes: 0
Views: 1166
Reputation: 1775
Spotted it - defined the user as a role and a name in global - changed it to
System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier = System.Security.Claims.ClaimTypes.Role
Never ceases to amaze me that I can bang my head for hours over something and as soon as I post the question............
Upvotes: 1