扩展CookieAuthenticationProvider OnValidateIdentity

时间:2014-09-11 06:29:20

标签: vb.net asp.net-mvc-5

我试图在用户被破坏或禁用时注销我的用户。我的赞成是在Startup.Auth.vb中扩展CookieAuthenticationOptins。根据许多例子,我发现我的Privider看起来像这样

app.UseCookieAuthentication(New CookieAuthenticationOptions() With {
        .AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        .LoginPath = New PathString("/Account/Login"),
        .Provider = New CookieAuthenticationProvider() With { _
        .OnValidateIdentity = Function(ctx)
                                  Dim ret = Task.Run(Function()
                                                         Dim userManager As UserManager(Of ApplicationUser) = New UserManager(Of ApplicationUser)(New UserStore(Of ApplicationUser)(New DatabaseContext()))
                                                         Dim currentUser = userManager.FindById(ctx.Identity.GetUserId())
                                                         If Not IsNothing(currentUser) Then
                                                             If currentUser.isBanned Or currentUser.isDeleted Then
                                                                 ctx.RejectIdentity()
                                                             End If
                                                         End If
                                                         Return Task.FromResult(0)
                                                     End Function)
                                  Return ret
                              End Function
        }})

不幸的是,这导致页面无限加载而没有错误。

修改 我添加了Return Task.FromResult(0),但我的用户仍然登录

0 个答案:

没有答案