ActiveReports 8 Server Administrator Guide
User Context for Multi-Tenancy

If you use ActiveReports, you can set UserContext attribute in your existing Page Report, RDL report or Section report and uload the report on ActiveReports 8 Server to provide information that is specific to the user that is logged into the server. You can set UserContext attribute as a value or in a connection string. Using this feature you can filter your report data depending on the user roles and attributes that you set. UserContext attribute is particularly helpful when you have multiple tenants who are logged on to the same portal and you want to restrict or filter the data available to each tenant.

Setting UserContext attribute as a Value

UserContext attribute can be set as a value in reports created in ActiveReports. These reports can then be uploaded on the ActiveReports 8 Server to view the output based on the UserContext attribute value that has been set. For example, if ActiveDirectory is set as a Security Provider on the Server, displayName securiy token can be used as a UserContext object.
Following steps will guide you through the procedure to set UserContext values in the Value property of a control.

Caution: Make sure the security token specified for the UserContext object is consistent with your Sercurity Provider settings.

For Page Report, RDL Report

  1. Add or select the control for which you want to set the UserContext.
  2. In the Properties window, enter the following expression in the Value property of the control.
    Expression
    Copy Code
    =Code.UserContext.GetValue("Your_Security_Token")
    

For Section Reports

  1. Add the control for which you want to set the UserContext.
  2. In the script tab of Section Report, add the following script. In this example, UserContext has been set in the Text property of TextBox control.
    Script
    Copy Code
    public void ActiveReport_ReportStart() {TextBox1.Text = UserContext.GetValue("Your_Security_Token"); }
    

Setting UserContext in Connection String

You can use any UserContext attribute in a connection string for reports created using ActiveReports. This is useful when each tenant in a multi-tenant application has a separate database, and you need to supply a dynamic value for the database.

In order to implement UserContext in a connection string, it is necessary to first complete your connection settings that is, connecting your report to an appropriate datasource, creating a data set and then re-placing datasource connection string with an expression having a Usercontext attribute. This is necessary because the ActiveReports does not have events to execute script code used for setting UserContext before data request.

For Page Report, RDL Report

  1. Complete the connection setting for your report. See Connecting a Report to a DataSource<CREATE LINK> for details.  
  2. Re-open the Datasource dialog and in the Connection String tab, replace the existing connection string with an expression having the UserContext attribute. See the following expression for SQL Server connection string.
    Connection String
    Copy Code
    "data source=ServerName;initial catalog=" + Code.UserContext.GetValue("Your_Security_Token") + ";user id=UserName;password=ServerPassword;"
    

For Section Reports

  1. Complete the connection setting for your report. See Connecting a Report to a DataSource<CREATE LINK> for details.
  2. Open the Script tab and add the following script to set UserContext attribute in an expression for SQL Server connection string.
    Script
    Copy Code
    public void ActiveReport_DataInitialize()
    {
    var _ds = rpt.DataSource as GrapeCity.ActiveReports.Data.SqlDBDataSource;
    _ds.ConnectionString = "data source=ServerName;initial catalog=" + UserContext.GetValue("Your_Security_Token") 
    
    + ";persist security info=False;user id=UserName;password=ServerPassword";
    }        
    

Setting UserContext as a Value for Parameter

UserContext attribute can be set as a Value for a Parameter to retrieve specific information for the user that is logged into the server. Following steps will guide you through the procedure to set UserContext attribute as a Value for Parameters.

For Page Report, RDL Report

  1. Open the Report Parameter dialog. See Add Parameters in a Page Report for details on How to add parameters.
  2. In the Available Values tab, select the select the Non-queried radio button and click the Add button.
  3. Enter the following expression in the Value property.
    Expression
    Copy Code
    =Code.UserContext.GetValue("Your_Security_Token")
    

For Section Reports

Note:  These steps assume that a Section Report is already bound to a DataSource. See Bind Reports to a Data Source for details.
  1. Open the Script tab and add the following script in the ReportStart event to set UserContext attribute as a Value for parameter in an expression for SQL Server connection string.
    Script
    Copy Code
    public void ActiveReport_ReportStart()
    {
     report1.Parameters["paramName"].Value = UserContext.GetValue("Your_Security_Token");
     GrapeCity.ActiveReports.Data.SqlDBDataSource ds = (GrapeCity.ActiveReports.Data.SqlDBDataSource) report1.DataSource;
     ds.SQL = "Select * from TableName where FieldName ='" + rpt.Parameters["paramName"].Value + "'";
    }
    

 

 


Copyright © 2015 GrapeCity, inc. All rights reserved

Support Forum