报告服务:使用带有本地 (RDLC) 报告的自定义程序集

发布于 2024-08-26 06:52:00 字数 320 浏览 3 评论 0原文

我正在设计一个将在 Winform 应用程序中以本地模式(RDLC 文件)使用的报告。我有一个带有静态类的自定义程序集,其中有一些我想在报表内部使用的函数(作为表达式)。

我已经找到了使用 RDL 报告执行此操作的各种帮助,但我的 RDLC 报告遇到了权限问题。

我在运行时收到以下错误: “报告引用了代码模块(我的模块),它不是受信任的程序集”。

我知道这是某种代码安全问题,但我不确定如何解决它。我在网上看到的文档是针对 RDL 报告的,它指导我编辑 SQL Server 特定的策略文件。我使用的是RDLC,所以不涉及sql server。我需要做什么才能获得适当的权限?

I am designing a report that will be used in local mode (an RDLC file) in a Winform app. I have a custom assembly with a static class that has some functions that I want to use inside of the report (as expressions).

I have found all sorts of help for doing this with RDL reports, but I'm running into a permissions problem with my RDLC report.

I get the following error at runtime:
"The report references the code module (my module), which is not a trusted assembly".

I know that this is some kind of a code security issue, but I'm not sure what to do to fix it. The documentation that I have seen online is aimed at RDL reports, and it instructs me to edit a SQL Server-specific policy file. I'm using RDLC, so there is no sql server involved. What do I need to do to acquire the appropriate permissions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

¢蛋碎的人ぎ生 2024-09-02 06:52:00

尝试使用 AddTrustedCodeModuleInCurrentAppDomain 方法
ReportViewer.LocalReport 属性 (reportViewer. LocalReport.AddTrustedCodeModuleInCurrentAppDomain(“您的程序集”))。

另请确保在程序集中使用 AllowPartiallyTrustedCallers 属性([程序集:AllowPartiallyTrustedCallers])。

Try using the AddTrustedCodeModuleInCurrentAppDomain method of the
ReportViewer.LocalReport Property (reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("your assembly")).

Also make sure you use the AllowPartiallyTrustedCallers attribute with your assembly ([assembly:AllowPartiallyTrustedCallers]).

一绘本一梦想 2024-09-02 06:52:00

AddTrustedCodeModuleInCurrentAppDomain 方法对于 .Net 4.0 已过时。 Visual Studio 2010 禁用此方法的调用。但是有 AddFullTrustModuleInSandboxAppDomain 方法ReportViewer 类的 LocalReport 属性 (reportViewer.LocalReport.AddFullTrustModuleInSandboxAppDomain(myAssemblyStrongName))。它需要程序集的强名称。我的应用程序在 Visual Studio 中执行正常,但当我从文件夹“bin”手动运行 exe 文件时,出现错误“报告引用了代码模块(我的模块),它不是受信任的程序集”。它可以是什么?

The AddTrustedCodeModuleInCurrentAppDomain method is obsolete for .Net 4.0. Visual Studio 2010 disable the call of this method. But there is the AddFullTrustModuleInSandboxAppDomain method in the LocalReport property of ReportViewer class (reportViewer.LocalReport.AddFullTrustModuleInSandboxAppDomain(myAssemblyStrongName)). It requires the strong name of the assembly. My application executes fine from Visual Studio but I get the error "The report references the code module (my module), which is not a trusted assembly" when I'm manually run exe-file from folder "bin". What it can be?

不知所踪 2024-09-02 06:52:00

@StefanHa 的评论提供了答案,以防博客文章消失,这里是对我有用的代码:

using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
rv.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions);
Assembly asm = Assembly.Load("MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
AssemblyName asm_name = asm.GetName();
rv.LocalReport.AddFullTrustModuleInSandboxAppDomain(new StrongName(new StrongNamePublicKeyBlob(asm_name.GetPublicKeyToken()), asm_name.Name, asm_name.Version));

我还需要设置 PermissionState.Unrestricted 而不是 PermissionState.None。在我的示例中,我正在加载 System.Web + System.Drawing,因此我只需要 SetBasePermissionsForSandboxAppDomain

@StefanHa's comment provides the answer, in case that blog post disappears here's the code that worked for me:

using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
rv.LocalReport.SetBasePermissionsForSandboxAppDomain(permissions);
Assembly asm = Assembly.Load("MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
AssemblyName asm_name = asm.GetName();
rv.LocalReport.AddFullTrustModuleInSandboxAppDomain(new StrongName(new StrongNamePublicKeyBlob(asm_name.GetPublicKeyToken()), asm_name.Name, asm_name.Version));

I also needed to set PermissionState.Unrestricted instead of PermissionState.None. In my example I was loading System.Web + System.Drawing and so I only needed up to the SetBasePermissionsForSandboxAppDomain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文