Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

How to get username and role

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("Admin.aspx")
        Else
            Server.Transfer("Order History.aspx")
        End If

    End Sub
0
whiwex
Asked:
whiwex
1 Solution
 
ericwong27Commented:
you can use the session to hold the user information
0
 
whiwexAuthor Commented:
explain more
I'm neew to this
0
 
kvimalCommented:
Session["Username"]=username1
0
 
iboutchkineCommented:
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.
Else
 Dont allow this page. Instead, redirect to the home page.
Response.Redirect(default.aspx)
End If
End Sub
0
 
whiwexAuthor Commented:
I just figured out that the user isn't being authenticated. The user is in asp.net configuration. I have created several users they all are created but authentication fails.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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