2015-04-17 187 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 
相關問題