Using user context data(from HttpContext) in the custom functions

Stimulsoft Reports.NET discussion
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,
HighAley wrote: Fri May 24, 2019 7:59 am You could pass a value of the variable as a parameter of this function.
yes, this how we do it now :) . However this is only a workaround because it requires user to pass some funny variable which does not have direct connection with real functionality.
Even worse, in some case it might be really a security issue because there is no way to guarantee authenticity of the provided information.

So we really need a real solution and not a workaround
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello.

Sorry, what kind of solution do you need?
The suggested solution is a typical way to pass a variable in such case.
What do you want to do with this variable?
Could you describe your scenario?

thank you.
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,

Let me repeat it again. I do not want to have any variable. I need to know in which context the report is executed without need to user copy dummy parameter for the call of every function. Below I copy the description provided before.
tayar wrote: Tue Mar 19, 2019 12:43 pm let me try to explain step by step.
* We have a multi-tenant system.
* User USR1 executing an async task to generate a report for tenant ABC subsidiary EFG.
* The report contains a custom function.
* Within this function I have to know that the generation is executed for "tenant ABC - subsidiary EFG", find appropriate DB connection, set some security restrictions for that user and subsidiary and retrieve some information which needs to be returned by the function with the restriction applied to this user.

So my context is USER - TENANT - SUBSIDIARY which I don't see how I can get while using static function.
As you see the information required in the function has real security affect.

Thanks
Vitaly
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello, Vitaly.

The report is a separate class where you could pass the necessary information.
You could do it using a variable. The variable will not be visible for users in the Viewer.
You could even create the variable in your code before running the report.
You could add any property to the report on the Code tab.
You could edit this code with your code outside of the report before the compilation.
You could run the function outside of the report and do all necessary modification of the report from code before its rendering.
There is a method (GetComponents()) that returns all components of the report.
So there are many different ways for you. You could choose anyof them.

Thank you.
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,

let's take a particular use case.
1. I have a 4 values which am retrieving in the report (Let's say A / B / C / D). They can come from different sources - DB / Business Objects / Report parameters
2. I have a certain setup in a tenant which defines formatting definition

I need to create a function which will be used in the report, which will accept these values as a parameters and return some result of the values based on the rules defined in point 2.
I do not know anything about what values will be passed and where they are coming from because the report is defined by the user.

What from the options you suggested is usable here?

Thanks
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello,

The first suggestion is to set the Culture property of the report.
It was in our first answer on March 13.

Till then your messages were with common description without any certain samples.
And now again. Why do you want to use the function? Why do you want to pass a parameter there?
There are many different solutions suggested here. We will make more specific answer when you send us a sample that reproduces your issue.

Thank you.
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,

What it has to do with a culture?
Let's give a names to the A / B / C from the previous example as FirstName/MiddleName/LastName/Title.
There is a setup defined in a tenant how it has to be formated. e.g `Title FirstName LastName`, or `Title LastName, FirstName`. Report retrieves this value as separate fields and function needs to read this setting and return a composite string according to the seting.
Is it more clear now?

Thanks
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello,

Yes, it's more clear now.
But you should call this function inside the report during the rendering.
So you could set the Culture property of the report or a variable that you could check during the rendering time.
And once again, such function should be called from inside of the report but not outside before the rendering.

Thank you.
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,

That's exactly the point. I am creating a function which is called during the rendering. But the functionality of this function has nothing to do with a Culture. It needs to read a setup of the tenant which executes the report.
And this is my problem - I don't know how to get the tenant info which (as I mentioned) I can not pass as a parameter.

Thanks
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello.

As we wrote you before you can pass necessary values with the variable.
You could create the variable with your code and it will not be visible to the users.
This is the typical way how information could be passed to the report.

Thank you.
Post Reply