listing users by profile values

K

kpg*

Hi all,

Trying to use the ASP.NET 2.0 membeship API to manage users
and user profiles, and of course, to provide role based security
to my web app.

I have several attributes I want to users, companyID for example,
so I'm using the profile feature to do this and it works great.

Now the problem:

My web app is used by several distincit groups of users as defined
by CompanyID. I want to have a page that lists all users associated
with a particular company.

So I want to write an object data source that returns all users
for a given companyID (which is stored in the profile table).

To do this I could query the user and profile tables directly, but
the profile data is stored as compound data in a single field - so
I'm not sure how to query that - there may well be some cool sql
mid string or regular expression function - I'm not a sql guru ;)

I also thought I could loop through all users (membership.getallusers)
and pull out the onses I want (based on companyID) and throw them in a
datatable. Problem here is I don;t know how to load the profile for a
user that is not the logged in user. I could not find any membership
methods that seem to do that.

Bottom line: I want to have access to user and user profile information
for non-logged on users returnable in a datatable and in as an efficient
manner as possible.

Getting users seems to be easy (but not all that efficient?) but getting
profile information (the stuff I really want) is elusive.

Am I making this too complex? Do I need to loop through all the users,
get their unique id, use that to pull the data from the profile table,
then parse the data field to see if that user is of the desired compnayID?

(whew)

Thanks
kpg
 
K

kpg*

I devised this solution which works fine. Any critiques welcome.

This is used as the datasource to an objectdatasource control that
is then bound to a gridview. The parameter if conveniently provided
by the logged-in user's profile, so it lists all users with the same
companyID as the logged-in user.

The total number of users will be in the hundreds rather than thousands
for my site, but I'm not sure how this routine will act with lots of
user to process. The Membership.GetAllUsers method also supports paging
which I may need to use to keep memory under control.

<code>
Imports Microsoft.VisualBasic
Imports system.ComponentModel
Imports System.Data
Imports System.Web.Security

<DataObject(True)> _
Public Class UserDB

<DataObjectMethod(DataObjectMethodType.Select)> _
Public Shared Function getAllUsersByCompanyID(ByVal compID As Integer)
As DataSet

Dim ds As DataSet = New DataSet
ds.Tables.Add("CompanyUsers")

Dim dt As DataTable = ds.Tables(0)
dt.Columns.Add(New DataColumn("UserName"))
dt.Columns.Add(New DataColumn("CompanyID"))
dt.Columns.Add(New DataColumn("AgencyID"))

For Each user As MembershipUser In Membership.GetAllUsers
'System.Diagnostics.Debug.WriteLine(user.UserName)

Dim userProfile As ProfileCommon = CType(ProfileBase.Create
(user.UserName), ProfileCommon)

If userProfile.CompanyID = compID Then
Dim row As DataRow = dt.NewRow
row.Item("UserName") = user.UserName
row.Item("CompanyID") = userProfile.CompanyID
row.Item("AgencyID") = userProfile.AgencyID
dt.Rows.Add(row)
End If

Next

Return ds

End Function

End Class
</code>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top