What I am trying to do
Authenticate a user, and redirect them to a page based on their role.
My issue
The first time entering correct credentials it fails. The user is authenticated, but when evaluating what role they are in, none of the if statements are true. The second time (after a post-back) it works as expected.
My question
Why does this not work; why do I have to authenticate a user, and post-back before the roles are set?
Code
Private Sub Login1_Authenticate(sender As Object, e As AuthenticateEventArgs) Handles Login1.Authenticate
If Membership.ValidateUser(Login1.UserName, Login1.Password) Then
FormsAuthentication.SetAuthCookie(Login1.UserName, False)
ToPage()
End If
End Sub
Private Sub ToPage()
If User.IsInRole("Role1") Then
Response.Redirect("~/Page1.aspx")
End If
If User.IsInRole("Role2") Then
Response.Redirect("~/Page2.aspx")
End If
If User.IsInRole("Role3") Then
Response.Redirect("~/Page3.aspx")
End If
End Sub
Use following it is in c# convert into VB
you can also use following