Search code examples
vb.netasp.net-identity

HttpContext.Current.User.Identity not populated after sign in


So I'm using AspNet Identity and I'm trying to access the User session variable in Http.Context.Current.User after signing in. I've read online that it should be automatically populated once the sign in attempt is successful. However this doesn't seem to be the case for me.

This is my code:

  Dim email As String = txtEmail.Text
            Dim password As String = txtPassword.Text
            Dim user As ApplicationUser

            If Session("LocalNetwork") Then
                Await _signInManager.PasswordSignInAsync(email, password, False, False))

                Dim y = HttpContext.Current.User.Identity.GetUserId

            End If

The signin is successful and I'm trying to access my UsersID but it returns null.

Web config:

<authentication mode="None" />

Anyone know why?


Solution

  • It's because I was checking if the user was authenticated in the same request as updating them. So they wont be authenticated until the end of the request.