How can I list all the users in a particular security group with ASP.NET?

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default How can I list all the users in a particular security group with ASP.NET?

    Does anyone know a way to list all the users in a particular windows
    security group on a .aspx web page? Thanks in advance!


    Brian Watkins Guest

  2. Similar Questions and Discussions

    1. Users group for View not for publish
      Hi guys, Does anybody can tell me how can I creat users group for view and not for publication? It's something like to create Contribute roles,...
    2. Exporting users that below to a certain group - windows 2003 active directory
      Is there any tool or script that will export the users names from a certain group from the active directory? I tried ldifde but it exports the cn...
    3. [OT] Director Users Group in São Paulo, Brazil
      If you live in Sao Paulo-Capital Help us, join us we intend to create a DUG (director users group) to discuss and divulge Director utilities so,...
    4. Group policy and traveling users
      Hello all, I have an issue with laptop users who take their laptops home, and group policies applied in the office. How do we deal with traveling...
    5. Olympus 4040 and 5050 users group
      http://groups.yahoo.com/group/Olympus4040_5050/ At 3090 members and 70 messages/day this is the largest and most active users group specific to...
  3. #2

    Default Re: How can I list all the users in a particular security group with ASP.NET?

    The first question is whether the group is a local machine group, an NT4
    domain group or an Active Directory group. If it is an AD group, the other
    question is whether you need nested membership or just direct membership.

    In either case, you should be using System.DirectoryServices to do these
    kinds of lookups. If you do some Google searches on
    microsoft.public.adsi.general you should see many many posts that will give
    you a good start.

    Another thing to consider is that it is often better to calculate a user's
    total group membership and compare the group to the user instead of
    comparing the user to the group.

    Joe K.

    "Brian Watkins" <raistlin19@aol.com> wrote in message
    news:e0srGXL8DHA.3288@TK2MSFTNGP11.phx.gbl...
    > Does anyone know a way to list all the users in a particular windows
    > security group on a .aspx web page? Thanks in advance!
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: How can I list all the users in a particular security group with ASP.NET?

    Joe,

    It is an Active Directory group. And I have yet to find an ASP.net specific
    example.

    I wrote a nifty app in VB.net that allowed me to search the AD for users and
    their departments. Of course when I convert the code to ASP.net and run it
    through the browser. Here is the code:


    <%@ Language="vb" Debug="True" %>
    <%@ Import Namespace="System" %>
    <%@ import namespace="System.Security.Principal" %>
    <%@ import namespace="System.DirectoryServices" %>
    <%@ import namespace="System.Web" %>
    <%@ Assembly name="System.DirectoryServices, Version=1.0.3300.0,
    Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>

    <HTML>
    <HEAD>

    <script runat="server" >
    Dim queryResults As SearchResultCollection
    Sub Page_Load()

    Dim rootEntry As New DirectoryEntry("LDAP://mydomain")
    Dim searcher As New DirectorySearcher(rootEntry)
    Dim result As SearchResult

    searcher.PropertiesToLoad.Add("cn")
    searcher.PropertiesToLoad.Add("mail")
    searcher.PropertiesToLoad.Add("SAMAccountName")
    searcher.PropertiesToLoad.Add("department")
    searcher.PropertiesToLoad.Add("MemberOf")
    searcher.PageSize = 5 'return 5 entries at a time
    searcher.ServerTimeLimit = New TimeSpan(0, 1, 0) 'tell the server to stop
    after one minute
    searcher.ClientTimeout = New TimeSpan(0, 2, 0)

    'server should stop before this time, but if not... client will timeout
    searcher.Sort.Direction = SortDirection.Ascending
    searcher.Sort.PropertyName = "Department"

    queryResults = searcher.FindAll()

    Call Print_Dept_List()

    End Sub

    Sub Print_Dept_List()
    Dim result As SearchResult, strDept As String, strOldDept As String
    Dim intX as integer = 0
    strOldDept = ""
    Dim myResultPropColl As ResultPropertyCollection

    For Each result In queryResults
    myResultPropColl = result.Properties
    Response.write("<p>The properties of the 'mySearchResult' are :")
    Dim myKey As String
    For Each myKey In myResultPropColl.PropertyNames
    Dim tab1 As String = " "
    Response.write("<p>" & myKey + " = ")
    Dim myCollection As Object
    For Each myCollection In myResultPropColl(myKey)
    response.write("<p>" & tab1 + myCollection & "</p>")
    Next myCollection
    Response.Write("</P>")
    Next myKey
    Response.Write("</P>")
    Next result
    End Sub
    </script>
    </Head>

    <body bgcolor="#FFFFFF"></body>
    </html>


    In my VB.net application runnning on my machine as me this code returns the
    properties I included in the searcher.PropertiesToLoad.Add statements.
    With the above code running on a webserver the only property that is
    returned is the adspath.

    Any idea why this is happening?



    Brian Watkins Guest

  5. #4

    Default Re: How can I list all the users in a particular security group with ASP.NET?

    Most errors in ASP.NET applications where serverless binding and default
    credentials are used are the result of anonymous binds being performed that
    limit you access to AD. Since ASP.NET runs a local machine account by
    default, ADSI and S.DS cannot use the current security context to infer a
    domain controller and domain credentials to use the for the bind.

    This is explained in much detail here:
    [url]http://support.microsoft.com/default.aspx?scid=kb;en-us;329986[/url]
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/troubleshooting_authentication_problems_on_asp_pag es.asp?frame=true[/url]

    If you add a DNS name in your path. a la LDAP://yourserver.com/path and add
    a username, password and AuthenticationTypes.Secure or
    AuthenticationTypesServerBind to your DirectoryEntry constructor, you will
    likely be successful.

    To read a groups membership, you just need to find the group and read it
    member attribute.

    If you want to get a user's complete security group membership, you need to
    look at the tokenGroups attribute. This is much prefered to memberOf for
    security purposes. I've written about this extensively in the other
    newsgroup, so doing a google groups search for Kaplan and tokenGroups in
    micrsoft.public.adsi.general should give you lots of hits and some good
    code.

    HTH,

    Joe K.

    "Brian Watkins" <raistlin19@aol.com> wrote in message
    news:u3Htk6M8DHA.1592@TK2MSFTNGP10.phx.gbl...
    > Joe,
    >
    > It is an Active Directory group. And I have yet to find an ASP.net
    specific
    > example.
    >
    > I wrote a nifty app in VB.net that allowed me to search the AD for users
    and
    > their departments. Of course when I convert the code to ASP.net and run
    it
    > through the browser. Here is the code:
    >
    >
    > <%@ Language="vb" Debug="True" %>
    > <%@ Import Namespace="System" %>
    > <%@ import namespace="System.Security.Principal" %>
    > <%@ import namespace="System.DirectoryServices" %>
    > <%@ import namespace="System.Web" %>
    > <%@ Assembly name="System.DirectoryServices, Version=1.0.3300.0,
    > Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>
    >
    > <HTML>
    > <HEAD>
    >
    > <script runat="server" >
    > Dim queryResults As SearchResultCollection
    > Sub Page_Load()
    >
    > Dim rootEntry As New DirectoryEntry("LDAP://mydomain")
    > Dim searcher As New DirectorySearcher(rootEntry)
    > Dim result As SearchResult
    >
    > searcher.PropertiesToLoad.Add("cn")
    > searcher.PropertiesToLoad.Add("mail")
    > searcher.PropertiesToLoad.Add("SAMAccountName")
    > searcher.PropertiesToLoad.Add("department")
    > searcher.PropertiesToLoad.Add("MemberOf")
    > searcher.PageSize = 5 'return 5 entries at a time
    > searcher.ServerTimeLimit = New TimeSpan(0, 1, 0) 'tell the server to stop
    > after one minute
    > searcher.ClientTimeout = New TimeSpan(0, 2, 0)
    >
    > 'server should stop before this time, but if not... client will timeout
    > searcher.Sort.Direction = SortDirection.Ascending
    > searcher.Sort.PropertyName = "Department"
    >
    > queryResults = searcher.FindAll()
    >
    > Call Print_Dept_List()
    >
    > End Sub
    >
    > Sub Print_Dept_List()
    > Dim result As SearchResult, strDept As String, strOldDept As String
    > Dim intX as integer = 0
    > strOldDept = ""
    > Dim myResultPropColl As ResultPropertyCollection
    >
    > For Each result In queryResults
    > myResultPropColl = result.Properties
    > Response.write("<p>The properties of the 'mySearchResult' are
    :")
    > Dim myKey As String
    > For Each myKey In myResultPropColl.PropertyNames
    > Dim tab1 As String = " "
    > Response.write("<p>" & myKey + " = ")
    > Dim myCollection As Object
    > For Each myCollection In myResultPropColl(myKey)
    > response.write("<p>" & tab1 + myCollection & "</p>")
    > Next myCollection
    > Response.Write("</P>")
    > Next myKey
    > Response.Write("</P>")
    > Next result
    > End Sub
    > </script>
    > </Head>
    >
    > <body bgcolor="#FFFFFF"></body>
    > </html>
    >
    >
    > In my VB.net application runnning on my machine as me this code returns
    the
    > properties I included in the searcher.PropertiesToLoad.Add statements.
    > With the above code running on a webserver the only property that is
    > returned is the adspath.
    >
    > Any idea why this is happening?
    >
    >
    >

    Joe Kaplan \(MVP - ADSI\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139