By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 1,952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

listing users by profile values

P: n/a
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?



Oct 18 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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.

Imports Microsoft.VisualBasic
Imports system.ComponentModel
Imports System.Data
Imports System.Web.Security

Public Class UserDB

Public Shared Function getAllUsersByCompanyID(ByVal compID As Integer)
As DataSet

Dim ds As DataSet = New DataSet

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

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
End If


Return ds

End Function

End Class
Oct 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.