2015-04-17 309 views
0

使用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 
+0

这个问题如此棘手或我的逻辑错误,因为没有人提出一个想法..? – tonics

回答

0

万一别人有这个问题,这是我的代码使用

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 
相关问题