Vb.net 在ValidateIdentity上扩展CookieAuthenticationProvider

Vb.net 在ValidateIdentity上扩展CookieAuthenticationProvider,vb.net,asp.net-mvc-5,Vb.net,Asp.net Mvc 5,当我的用户被屏蔽或禁止时,我试图注销他们。我的方法是在Startup.Auth.vb中扩展CookieAuthenticationOptions。根据许多例子,我发现我的私家车是这样的 app.UseCookieAuthentication(New CookieAuthenticationOptions() With { .AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, .Log

当我的用户被屏蔽或禁止时,我试图注销他们。我的方法是在Startup.Auth.vb中扩展CookieAuthenticationOptions。根据许多例子,我发现我的私家车是这样的

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
        }})
不幸的是,这会导致无休止地加载页面而不会出错

编辑:
我添加了返回任务。FromResult(0),但我的用户仍在登录

Ok,现在似乎可以工作了。。Task.FromResult(0)完成了此工作