Welcome Guest! To enable all features please Login or Register.



Go to last post Go to first unread
#1 Posted : Friday, June 26, 2020 8:54:34 AM(UTC)

Rank: Member

Groups: Registered
Joined: 6/5/2020(UTC)
Posts: 12

Thanks: 4 times

what is the proper way to define class variable in razor scripts ? All the examples starts by defining a variable from a Model, which I assume is a "global" variable defined based on the context.

ReportModel model = Model;

For example I would like to use class SecurityUser in Pre SQL statement of MetaData/SQL model so I tried


@using Seal.Model
SecurityUser UserClass; // = ?
string result = "select '"+UserClass.WebUserName+'"';

But error "Use of unassigned local variable 'UserClass'" is shown.

ps: I am new to Seal Report and have no experience in Razor language

Edited by user Friday, June 26, 2020 9:25:04 AM(UTC)  | Reason: Not specified

#2 Posted : Saturday, June 27, 2020 3:39:36 PM(UTC)

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 991

Thanks: 14 times
Was thanked: 170 time(s) in 164 post(s)
A razor script is executed with one instance of an object class...
The type of the object depends on the script.

For the pre-sql statement, the object is a MetaTable,
if you want the security context from this when the table is involved in a query, you should adapt the following sample:
    MetaTable table = Model;
    Environment.UserName; //This gives the windows user of the process running the engine
    if (table.Source.Report != null && table.Source.Report.SecurityContext != null)
        var securityContext = table.Source.Report.SecurityContext; //User is logged through a Web Report Servert and has a context
        securityContext.Name; //Name of the user set during the login
        securityContext.WebUserName; //Name got from the login window
        //securityContext.SecurityGroups; //List of security groups set for the user
        if (securityContext.BelongsToGroup("Default Group")) { //Test if the user belongs to a group
            //Special restriction here

Got from https://sealreport.org/Recipes#lineDynamicSecurity

Edited by user Saturday, June 27, 2020 3:40:51 PM(UTC)  | Reason: Not specified

thanks 1 user thanked epf for this useful post.
cyracks on 6/28/2020(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.