Get username and identity right after successful login
I am using ASP.NET Identity 2.0.
After a successful login, I want to get the username and id (of the successfully logged in user).
I have tried to no avail
If IsValid Then
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim signinManager = Context.GetOwinContext().GetUserManager(Of ApplicationSignInManager)()
Dim result = signinManager.PasswordSignIn(UName.Text, Password.Text, RememberMe.Checked, shouldLockout:=False)
Select Case result
Case SignInStatus.Success
Tried this after SignInStatus.Success
Dim usid = signinManager.GetVerifiedUserId
or
Dim usid =User.Identity.Name
or
Dim usid = User.Identity.GetUserId
I can get user id and name on page reload. But I cannot reload the page programmatically via
Response.Redirect(Request.RawUrl)
Or
ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "reload", "reloadPage()", True)
What am I doing wrong? Note. I am using jQuery Mobile on this page.
+3
source to share
2 answers
Well, I decided to use a little common sense instead of wrestling with the code or API (timing is important too !!) After the user has successfully signed in (Case SignInStatus.Success), then why would you be fussy, I get this particular user using the username he entered.
Dim thisUser = manager.FindByName(UName.Text)
Then get other information
Dim thisUserId As String = thisUser.Id.ToString
Dim thisUserEmail As String = thisUser.Email
etc. etc.
0
source to share