How to get username and role

Posted on 2007-07-23
Last Modified: 2008-01-09
After as user logs into a web page how do you get the usersname and he role. I need to send users of different role to different pages. Here's the code I have been trying
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        Dim username1 As MembershipUser = Membership.GetUser
        Dim returnvalue As Boolean
        returnvalue = Roles.IsUserInRole("username1", "Administrators")
        If returnvalue = True Then
            Server.Transfer("Order History.aspx")
        End If

    End Sub
Question by:whiwex
    LVL 10

    Expert Comment

    you can use the session to hold the user information

    Author Comment

    explain more
    I'm neew to this
    LVL 5

    Expert Comment

    LVL 28

    Accepted Solution

    The User object also provides a method called IsInRole which is designed to let you
    evaluate whether a user is a member of a group. For example, a user who is a member
    of an Administrators group can be given more access rights.

    Private Sub Page_Load(sender As Object, e As EventArgs) _
    Handles MyBase.Load
    If User.IsInRole(Administrators)
     Do nothing, the page should be accessed as normal because
     the user has administrator privileges.
     Dont allow this page. Instead, redirect to the home page.
    End If
    End Sub

    Author Comment

    I just figured out that the user isn't being authenticated. The user is in configuration. I have created several users they all are created but authentication fails.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now