How Do I Get the ASPNet Login Role for the user logged in?

Topics: Developer Forum, Project Management Forum
Mar 30, 2011 at 3:54 PM

How Do I Get the ASPNet Login Role for the user logged in?


I'm after something like:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        txtUserName.Text = User.Identity.Name        ' txtUserLevel.Text = Roles.GetRolesForUser(txtUserName.Text)    

End Sub

where I load a text box with the logged in users' level or Role.


Any ideas?
Thanks much

,Dave

Mar 30, 2011 at 6:40 PM

Hi Dave,

If I understand you correctly, you should be able to achieve this via the following

C#:

string userName = Context.User.Identity.Name;
string userRole = Roles.GetRolesForUser(userName).ToString();
txtUserName.Text = userName;
txtUserLevel.Text = userRole;

VB:

Dim userName As String = Context.User.Identity.Name
Dim userRole As String = Roles.GetRolesForUser(userName).ToString()
txtUserName.Text = userName
txtUserLevel.Text = userRole

Hope this helps,

Bjorn