• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 693
  • Last Modified:

ASP.NET -- Redirect user based on role

In the code below, I am trying to get the users role, and redirect them to the appropriate page.  The problem is that the first time I try to login, both ticketmasters and admin roles are false, but the second time I try logging in, the correct role is detected.  This is driving me nuts.  Can anyone point out where I am going wrong?



    Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '
        ' Login Ticketmasters or Admins
        '
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Debug.Print(Roles.IsUserInRole("Admins").ToString)
        Debug.Print(Roles.IsUserInRole("TicketMasters").ToString)
        Dim strRole As String = Roles.GetRolesForUser(Login1.UserName).ToString
        Debug.Print(strRole)

        If Roles.IsUserInRole("Admins") Then
            Response.Redirect("~/game/admin/default.aspx")
        End If
0
rrhandle8
Asked:
rrhandle8
  • 2
1 Solution
 
rrhandle8Author Commented:
Answered my own question. I was not including the username

Debug.Print(Roles.IsUserInRole(Login1.UserName, "Admins").ToString)
0
 
rrhandle8Author Commented:
Answered it myself before anyone else made any comments.
0
 
jagssiduralaCommented:
i think you need to change the following code:

 If Roles.IsUserInRole("Admins") Then
            Response.Redirect("~/game/admin/default.aspx")
else Roles.IsUserInRole(strRole) Then
 //redirection to other page based on role......
 End If
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now