PortSight Secure Access Documentation

Checking User's Membership

 

In this tutorial you will learn how to check if user is member of particular group.

  1. Open your project with Secure Access authentication implemented. Add a new page called CheckMembership.aspx.

  2. Add following lines at the beginning of the page code-behind, so that you can use Secure Access libraries in this page.

    [Visual Basic]
    
    Imports PortSight.SecureAccess.ARDataServices
    Imports PortSight.SecureAccess.ARObjects
    
    
    [C#]
    
    using PortSight.SecureAccess.ARDataServices;
    using PortSight.SecureAccess.ARObjects;								
  3. Put a new button called "Button1" and a new label called "Label1". Double-click the button and you will see the event handler Button1_Click for this button. Add following lines to this method:

    [Visual Basic]
    
    Dim ticket As ARUserTicket = CType(Session("ARUserTicket"), ARUserTicket)
    
    If ticket.IsMemberAll("PMs") Then
        Label1.Text = ticket.ObjectName & " is member of the PMs group."
    Else
        Label1.Text = ticket.ObjectName & " is NOT member of the PMs group."
    End If
    
    
    [C#]
    
    ARUserTicket ticket = (ARUserTicket) Session["ARUserTicket"];
    
    if (ticket.IsMemberAll("PMs"))
    {
    	Label1.Text = ticket.ObjectName + " is member of the PMs group.";
    }
    else
    {
    	Label1.Text = ticket.ObjectName + " is NOT member of the PMs group.";
    }										

    What you did

    You created a new page that displays a message if user is member of the "PMs" user group. You used user ticket that is created when the user logs on and stored in the session variable. This scenario is useful for repeating tasks, since the membership and other information are cached in this user ticket and you needn't connect to the database for every request. If you still don't want to use the session variables you can execute ARHelper.IsMemberAll or ARUser.IsMemberAll methods instead - see ARObjects classes documentation to find more information.

  4. Now open the Secure Access user interface, create a new user group named "PMs", view its details and check that its object alias is "PMs". Add the user account you use for testing as a member of the "PMs" group.

  5. Compile and run your application. Log on and navigate to the CheckMembership.aspx page. You should see the text saying that you are member of the "PMs" group.

        Note

    When calling methods such as "IsMember" you always need to use the object alias instead of its name. Using the alias instead of name or ID allows you to avoid re-coding your application when object name is changed (e.g. the name of the department may change or may be translated in a foreign office; the ObjectID may be different when you deploy your application from the development environment to the main server).