VB Redirect to Different Page After Login - Based on Role

Last post 07-05-2008 6:12 AM by jpcoliveros. 6 replies.

Sort Posts:

  • VB Redirect to Different Page After Login - Based on Role

    10-22-2007, 9:49 PM
    • Member
      26 point Member
    • kristine1991
    • Member since 07-20-2007, 4:25 PM
    • Posts 60

    I have two different pages I need to redirect to, based on the Role someone is in.  I have tried a few different ways, but no luck.... No matter what role the person is in they are redirected to the Else URL.  If anyone can tell me a way to do this, I will greatly appreciate it.

    Below are a couple of the codes I used. 

     

    Protected Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoggedIn

    If User.IsInRole("Client") Then

    Response.Redirect("~/proof.aspx")

    Else

    Login1.DestinationPageUrl = ("~/RunSheet.aspx")

    End If

    End Sub

     

    Also Have Tried this under Protected Sub Page_Load:

    If User.IsInRole("Client") Then

    Login1.DestinationPageUrl = ("~/Proof.aspx")

    Else

    Login1.DestinationPageUrl = ("~/RunSheet.aspx")

    End If

     

    Thanks,
    Kristine

    Thanks,

    Kristine
  • Re: VB Redirect to Different Page After Login - Based on Role

    10-22-2007, 10:15 PM
    Answer
    • Member
      26 point Member
    • kristine1991
    • Member since 07-20-2007, 4:25 PM
    • Posts 60

    I got it to work using this under Page_Load.... Is there a better way to do it?  Or is this fine.

            If Request.IsAuthenticated AndAlso User.IsInRole("Client") = True Then
                Response.Redirect("~/Proof.aspx")
            ElseIf Request.IsAuthenticated AndAlso User.IsInRole("Client") = False Then
                Response.Redirect("~/RunSheet.aspx")
            End If

    Thanks,
    kristine

    Thanks,

    Kristine
  • Re: VB Redirect to Different Page After Login - Based on Role

    01-10-2008, 3:31 PM
    • Member
      44 point Member
    • jazzbo
    • Member since 12-14-2005, 8:04 AM
    • Posts 27

    I'd say it's perfectly fine; it's the way I've been doing it for a couple years.

  • Re: VB Redirect to Different Page After Login - Based on Role

    06-30-2008, 10:05 AM
    • Member
      8 point Member
    • zetfactor
    • Member since 05-30-2008, 7:05 PM
    • Posts 11

     hi, i used the same code as yours

     

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Request.IsAuthenticated AndAlso User.IsInRole("client") = True Then
                Response.Redirect("~/Default.aspx")
            ElseIf Request.IsAuthenticated AndAlso User.IsInRole("client") = False Then
                Response.Redirect("~/ManageUsers.aspx")
            End If

        End Sub

     

    Default.aspx is my home page, ManageUsers.aspx is only authorized for admins, 

    but it keeps loggin me back to Default.aspx even when i login with my admin account which is already assigned to the Administrator Role

     

    thanks

     

  • Re: VB Redirect to Different Page After Login - Based on Role

    07-04-2008, 7:03 PM
    • Member
      26 point Member
    • kristine1991
    • Member since 07-20-2007, 4:25 PM
    • Posts 60

    The only thing I can think of is that you don't actually have a Role named client.

     Let me know if you do for sure, and I'll pull out the project and take a closer look.

    Thanks,
    Kristine

     

    Thanks,

    Kristine
  • Re: VB Redirect to Different Page After Login - Based on Role

    07-04-2008, 7:38 PM
    • Member
      8 point Member
    • zetfactor
    • Member since 05-30-2008, 7:05 PM
    • Posts 11

     i do have a role named Client, i also tried to use my Admin role, but its just as if i didnt write the code, keeps taking me to my default home page..

    i wanted this code because i want it to redirect the Admin to the Users Management Page, without using a link on my home page.. i want to keep my design clean..

     

    thanks for help 

  • Re: VB Redirect to Different Page After Login - Based on Role

    07-05-2008, 6:12 AM
    • Contributor
      2,622 point Contributor
    • jpcoliveros
    • Member since 01-06-2006, 6:54 AM
    • Philippines
    • Posts 376

            If Request.IsAuthenticated AndAlso User.IsInRole("client") = True Then
                Response.Redirect("~/Default.aspx")
            ElseIf Request.IsAuthenticated AndAlso User.IsInRole("client") = False Then
                Response.Redirect("~/ManageUsers.aspx")
            End If

    This one should work. However, ensure that these roles are defined in your role provider. Otherwise, you will be redirected to the default (not necessarily the default.aspx page). Also, check if the user has a defined role. You can create users with the Membership API even without adding an associated role to it. 

    Patrick Oliveros
    superpatrick.wordpress.com
Page 1 of 1 (7 items)