listing users by profile values

Discussion in 'ASP .Net' started by kpg*, Oct 18, 2007.

  1. kpg*

    kpg* Guest

    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?


    kpg*, Oct 18, 2007
    1. Advertisements

  2. kpg*

    kpg* Guest

    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

    <DataObject(True)> _
    Public Class UserDB

    <DataObjectMethod(DataObjectMethodType.Select)> _
    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
    kpg*, Oct 19, 2007
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JL
  2. Sunil Miriyala
    Sunil Miriyala
    Mar 1, 2004
  3. Brad
    Roedy Green
    Jul 19, 2005
  4. Andy B
    Andy B
    May 3, 2008
  5. Steven
    Oct 24, 2008