Announcement

Collapse
No announcement yet.

Checking users group membership (ASP)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checking users group membership (ASP)

    Hi all

    I have adapted a logon script written in VB Script to include it in a web page. It will look at group membership and then show certain links depending on what groups they are a member of:

    Code:
    <%
    Dim Strgroups
    
    Const STAFF_GROUP = "cn=staff"
    Const STUDENT_GROUP = "cn=student"
    
    Set ADSysInfo = CreateObject("ADSystemInfo")
    Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
    
    strGroups = LCase(Join(CurrentUser.MemberOf))
    
    If InStr(strGroups, STAFF_GROUP) Then
    %>
    <a href="http://capitawebservices/internetbuilder">Columbus</a>
    <%
    
    End If
    
    %>
    But it works for a member of the staff group but if a user that isn't a member trys to look at the page they get:
    Code:
    Error Type:
    Microsoft VBScript runtime (0x800A000D)
    Type mismatch: 'Join'
    /default-test.asp, line 41
    
    
    Browser Type:
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) 
    
    Page:
    GET /default-test.asp
    Any thoughts on how i can fix this?
    Server 2000 MCP
    Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

  • #2
    Re: Checking users group membership (ASP)

    It sounds like the 'CurrentUser.MemberOf' is not returning a collection. Try altering the code as follows:


    Code:
    <%
    Dim Strgroups
    
    Const STAFF_GROUP = "cn=staff"
    Const STUDENT_GROUP = "cn=student"
    
    Set ADSysInfo = CreateObject("ADSystemInfo")
    Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
    
    If IsArray(CurrentUser.MemberOf) Then
            strGroups = lcase(CurrentUser.MemberOf)
    Else
            strGroups = LCase(Join(CurrentUser.MemberOf))
    End If
    
    
    If InStr(strGroups, STAFF_GROUP) Then
    %>
           <a href="http://capitawebservices/internetbuilder">Columbus</a>
    <%
     End If
    %>

    Comment


    • #3
      Re: Checking users group membership (ASP)

      Thanks for the info mate. It works (except needed to swap the LCase(Join(CurrentUser.MemberOf)) and LCase(CurrentUser.MemberOf) )

      And it is because the user i was testing that wasn't in the staff group was only in one group and thus the join had nothing to join the only group to!

      Thanks for the fix.
      Server 2000 MCP
      Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      Comment


      • #4
        Re: Checking users group membership (ASP)

        Not a problem. That's what were here for.

        Microsoft is going to fix that problem in their next release of Windows Script 5.6 so the check isn't needed.

        Comment

        Working...
        X