Asp.net 2.0 Authoritation by roles

J

Juan Puebla

Hi,

I try to redirect users to specific pages depending on roles:

If Membership.ValidateUser(TextBox1.Text, TextBox2.Text) Then
'Membership.ValidateUser(TextBox1.Text, TextBox2.Text) Then


Dim encryptedStr As String
Dim cookie As HttpCookie
Dim ticket As New FormsAuthenticationTicket(1, TextBox1.Text,
Now(), Now().AddMinutes(60), False, "IdCliente")

encryptedStr = FormsAuthentication.Encrypt(ticket)

cookie = New HttpCookie(FormsAuthentication.FormsCookieName,
encryptedStr)

Response.Cookies.Add(cookie)



If Roles.IsUserInRole("Parents") Then

Response.Redirect("AppsHtml/Roles/Parents.aspx", True)

ElseIf Roles.IsUserInRole("Director") Then

Response.Redirect("AppsHtml/Roles/Directors.aspx", True)

ElseIf Roles.IsUserInRole("Professor") Then

Response.Redirect("AppsHtml/Roles/Professors.aspx", True)


End If



Else

Label3.Visible = True


End If

When I try this I fill Login and password in textboxes and press the button.
I have to press the button twice to get redirected to the page for the role.
It seems that I need a round trip to get the user authenticated.

Any help?

thanks

Juan
 
D

Dominick Baier [DevelopMentor]

Hello Juan,

you set the cookie - but only after a postback the roles are available using
IsInRole

you can use Roles.IsUserInRole(username, role);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top