473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

listing users by profile values

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

Oct 18 '07 #1
1 1986
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>
Oct 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: SU News Server | last post by:
I've struggled with this for quite a while and I'm am just not sure what is going on. I have the following code import os def buildList( directory='/Users/mkonrad' ) dirs = listing =...
2
by: Rodusa | last post by:
I am trying to Synchronize anonymous users with authenticated uses using Profile_MigrateAnonymous. However Profile_MigrateAnonymous only carries information in one direction, for instance, if I...
6
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base...
2
by: Darius | last post by:
Hello I implemented custom profile provider based on the example at http://msdn2.microsoft.com/en-us/library/ta63b872.aspx. It reads Profiles values from tables in Sql Server. Everytime when...
9
by: Eric Falsken | last post by:
I've added a number of additional properties to my profile. Sometimes, the values are populated when the user is retrieved from the database, but sometimes the values are empty/default. How can I...
1
by: ashish | last post by:
hi all, I am writing a custom profile provider to save my business object as one of the properties of the profile however i am facing a problem' the HttpContext.Current.Session property is...
11
by: Weston Weems | last post by:
I've got the need to have user information for logged in user in a readily avaliable page context (a lot like how Profile is) except not suck. Before we jump to any conclusions, from what I...
2
by: Bart | last post by:
Hallo, i defined some profile properties (category and department), for our membership users.. I also made a list of all the membership users in a gridview. This list shows only the username...
5
by: Steven | last post by:
I have the following in my web.config: <system.web> <profile defaultProvider="MyASPSqlProfileProvider" enabled="true" > <properties> <add name="FirstName" defaultValue="" type="string"/> <add...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.