Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > listing users by profile values

Reply
Thread Tools

listing users by profile values

 
 
kpg*
Guest
Posts: n/a
 
      10-18-2007
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

 
Reply With Quote
 
 
 
 
kpg*
Guest
Posts: n/a
 
      10-19-2007
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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<profile><properties> with no Profile class Steven ASP .Net 5 10-24-2008 07:23 PM
Visual Studio 2008 asp.net web administration>profile: "The profile wasn't created"? Andy B ASP .Net 0 05-03-2008 05:15 PM
Want to profile monitor for Fuji Frontier ICC profile? Lynn Digital Photography 9 09-08-2005 12:17 PM
Java Web Start app icons keep going in user profile not All Users profile Brad Java 1 07-19-2005 02:10 AM
Reg. Listing Only Online Users in a Seperate JTree from the Total Users. Sunil Miriyala Java 0 03-01-2004 04:58 PM



Advertisments