Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Get User and RolesGet User and Roles
Previous
 
Next
New Post
1/29/2008 12:52 AM
 

Hi all,

How do I retrieve the the user id that is currently logged on and also the roles they belong to?

Many thanks!

 
New Post
1/29/2008 2:00 AM
 

Richard, you can use UserController.GetCurrentUserInfo() to retrieve information about logged on user. For example :

UserInfo uinfo = UserController.GetCurrentUserInfo();
// do whatever you want, for example to retrieve first name and lastname :

string username = uinfo.FirstName + " " + uinfo.LastName; // or you can use DisplayName

To retrieve it's role, you can use : uinfo.Roles(). it's an array, so you can enumerate using collection approach.

HTH.

 
New Post
3/26/2008 9:28 AM
 

Here is an example I use with my custom controls:

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)Dim showRoles As String = ""

 

 

Dim mUser As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfoFor Each i As String In mUser.Roles
showRoles += i.ToString() &
","
Next

 

Me.Label1.Text = "User Name: " & mUser.Username
Me.Label1.Text += "<br> Full Name: " & mUser.DisplayName
Me.Label1.Text += "<br> UserID: " & mUser.UserID.ToString
Me.Label1.Text += "<br> Roles: " & showRolesEnd Sub

 

 

 

 


View Brenden Kehren's profile on LinkedIn
 
New Post
5/26/2008 6:33 PM
 

Even more options (at least shorter);

//first option
        UserInfo usuari = this.UserInfo;
        Label1.Text = usuari.Username;
        

//second option
        Label1.Text = HttpContext.Current.User.Identity.Name;


ege
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Get User and RolesGet User and Roles


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out