In a controller: getting name of current user?

Topics: Writing modules
May 21, 2011 at 5:07 PM

In a controller, what call should I make to get the name of the current user and what roles he belongs to?

May 24, 2011 at 3:01 PM

To get the user object that will have user info, you could use Membership.GetUser(). To get the user's actual name, Membership.GetUser().UserName.

To return the list of roles a user is in, see this thread on Stackoverflow:

http://stackoverflow.com/questions/2068445/get-current-users-role

May 24, 2011 at 3:44 PM

Although -  you might want to use WorkContext.CurrentUser (which accesses the User content item in Orchard) and IRolesService which is an orchard component to inspect the current roles.