MVC退出声明身份验证

时间:2015-08-14 16:45:33

标签: asp.net-mvc security

远离Forms身份验证并试图了解Claim Identity用户可以使用此

成功登录
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()会起作用,但我得到'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 个答案:

答案 0 :(得分:1)

发现它 - 将用户定义为角色和全局名称 - 将其更改为

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

永远不要让我感到惊讶,因为我可以在某些事情上敲打我的脑袋,并在我发布问题后立即............