2015-08-14 72 views
0

从表单验证远离,并尝试能够成功让我的索赔周围用户的身份登录头使用此MVC登出声明身份验证

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) 

但与注销的问题 - 我想AuthenticationManager.Signout( )会工作,但我得到'退出不是AuthenticationManager的成员',所以现在有点难倒了。

这是全球

System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier = System.Security.Claims.ClaimTypes.Name 

我想这在注销控制器

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 

但返回错误

A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name' was not present on the provided ClaimsIdentity. 

当它击中

@Html.AntiForgeryToken() 

有什么想法?

感谢

回答

1

察觉到而已 - 定义用户的角色和在全球的名称 - 把它改为

System.Web.Helpers.AntiForgeryConfig.UniqueClaimTypeIdentifier = System.Security.Claims.ClaimTypes.Role 

从未停止给我带来惊喜,我可以通过什么的一声我的头几个小时,只要我发布问题............