Wierd results with Roles.IsUserInRole

V

VB Programmer

I am using the Login control with ASP.NET 2.0.

I want the redirect page to go to a page BASED on the role the user is in.
Here's my code:

Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Login1.LoggedIn
If Roles.IsUserInRole("SiteAdministrator") = True Then
Response.Redirect("AdminsOnly/AdminHome.aspx")
Else
Response.Redirect("MembersOnly/MemberHome.aspx")
End If
End Sub

When I debug it and print this with a result of "True":
? Roles.IsUserInRole("SiteAdministrator") = True

I've also tried this with a result of "True":
? Roles.IsUserInRole(Me.Login1.UserName.ToString , "SiteAdministrator")

But, it KEEPS skipping to the Else part. Any ideas why? Any suggestions?

Thanks.
 
G

Guest

Dear VB Programmer,
It may be the roles using IsInRole to be available after postback

Hope can help you!
Regards,
Joe Tsui
 
G

Guest

Dear VB Programmer,
It may be :
Before the page finishing "End Sub", the
Roles.IsUserInRole("SiteAdministrator")
is still false

After the page finishing "End Sub", and then postback,
Roles.IsUserInRole("SiteAdministrator") will change to true

So Roles.IsUserInRole will be false if the page does not postback to the
server
and always ELSE

Hope can help you!
Regards,
Joe Tsui
 

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,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top