当他确认电子邮件地址时登录用户

Login the user when he confirms the email address

使用 Microsoft.AspNet.Identity 我几乎拥有管理用户问题所需的一切,但我(vb.net 初学者)无法更新此代码以在用户确认时自动登录电子邮件地址。

我想我需要一种方法来仅基于 UsedId 获取 ApplicationUser

这是我尝试更改的代码:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim code As String = IdentityHelper.GetCodeFromRequest(Request)
    Dim userId As String = IdentityHelper.GetUserIdFromRequest(Request)
    If code IsNot Nothing AndAlso userId IsNot Nothing Then
        Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
        Dim result = manager.ConfirmEmail(userId, code)
        If result.Succeeded Then
       '>>>>>>>>login the user  
            successPanel.Visible = True
            Return
        End If
    End If
    successPanel.Visible = False
    errorPanel.Visible = True      
End Sub

如果其他人有这个问题,这是我使用的代码

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim code As String = IdentityHelper.GetCodeFromRequest(Request)
    Dim userId As String = IdentityHelper.GetUserIdFromRequest(Request)
    If code IsNot Nothing AndAlso userId IsNot Nothing Then
        Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
        Dim result = manager.ConfirmEmail(userId, code)
        If result.Succeeded Then
            Try

                Dim task = New UserStore(Of Sue.ApplicationUser)(Context.GetOwinContext().[Get](Of ApplicationDbContext)()).FindByIdAsync(userId)
                Dim user = task.Result()

                Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)()

                signInManager.SignIn(user, isPersistent:=False, rememberBrowser:=False)

                Context.Response.Redirect("/Account/UserData", False)

            Catch ex As Exception
                successPanel.Visible = False
                errorPanel.Visible = True
                Return
            End Try
        End If
    End If
    successPanel.Visible = False
    errorPanel.Visible = True
End Sub