SSRS 2008 R2 how to get the logged user Group information
Hi, I am using SSRS 2008 R2, for the windows login I am able to get the domain and user name(domain\username) by using the the built in fields User!UserID in the expression. I had the requirement to use the Active Directory and it contains several groups and users.I have provided the permissions to the groups to browse the reports from the site and folder settingin the report manager.Is it possible to get the groupname by any expressions ? now I am only getting the systemname\username by User!UserID. I have to get the groupname for which the user belong. Thanks, Shyam
August 13th, 2010 7:18am

There is no build-in functionality in RS. Please consider writing custom code or external assembly. Pay attention to code security.Have fun with Reporting Service
Free Windows Admin Tool Kit Click here and download it now
August 13th, 2010 10:22pm

Hi Shyam, As Xiaoguang mentioned, we need to use custom code to get the user's group membership. Below is the code for you reference: Public Function GetUserMembership(ByVal strUser As String ) As String Dim groups As String Try Dim obEntry As New System.DirectoryServices.DirectoryEntry("LDAP://DC=aw,DC=com") Dim srch As New System.DirectoryServices.DirectorySearcher(obEntry, "(sAMAccountName=" & strUser & ")") Dim res As System.DirectoryServices.SearchResult = srch.FindOne() If res IsNot Nothing Then Dim obUser As New System.DirectoryServices.DirectoryEntry(res.Path) ' Invoke Groups method. Dim obGroups As Object = obUser.Invoke("Groups") For Each ob As Object In DirectCast(obGroups, System.Collections.IEnumerable) ' Create object for each group. Dim obGpEntry As New System.DirectoryServices.DirectoryEntry(ob) groups = groups + obGpEntry.Name + ";" Next End If Catch ex As Exception groups = "" End Try Return groups End Function To use the code, please use this expression: =Code.GetUserMembership(Split(User!UserUD, "\")(1)) For more information, please see: How to use custom assemblies or embedded code in Reporting Services: http://support.microsoft.com/kb/920769 How to get the list of groups that a user is a member of: http://www.codeproject.com/KB/dotnet/usergroupmembership.aspx If you have any more questions, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
August 16th, 2010 3:42am

Thankyou ! Jim , Xiaoguang
Free Windows Admin Tool Kit Click here and download it now
August 26th, 2010 1:53am

Hi there, Thanks for the code. I've tried implementing it and am getting the following error in my BIDS environment: Request for the permission of type 'System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed. I understand how to set the partial trust settings on the server and my execution account is a domain user, however how do I set the partial trust when Visual Studio renders the report? I am using Windows 7 with SSRS 2008 R2 running as a domain user. Thanks in advance.
October 12th, 2010 2:14pm

Hi This code works great, until I deploy the report to the report server. From the comments so far, I understand that I will need to make changes to the Security settings on the server so this code can run.. I have no idea how to do this, can anyone point me in the right direction ? Thanks for you time Phil
Free Windows Admin Tool Kit Click here and download it now
March 29th, 2011 9:54am

Hi Jin Chen, I also need your code thats written above. I tried to use it in a report (SQL Reporting Services 2008 R2),but I got the following error message: The term that refers to a UserUD element is not present in the user list. Take care that the correct term is used for words also as letters. Do you have any idea what to do? Thanks, Skeeve
June 10th, 2012 2:45pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics