LocalReport (WebForms) 和部分信任,用于 PDF 生成

发布于 2024-10-09 21:00:43 字数 382 浏览 0 评论 0原文

我的目标是生成一个 PDF 以在网页中显示,无论是作为 aspx 还是使用通用处理程序。 (这将从 Silverlight 页面链接,但这与问题无关。)

问题是 LocalReport(Microsoft.Reporting.WebForms;Microsoft.ReportViewer.WebForms.dll)需要完全信任,而我们的托管服务器不允许完全信任相信。我知道 ReportViewer 有一个远程模式,允许它以部分信任的方式运行,但为此我需要一个报表服务器 URL,它可能也应该具有完全信任,但这并不能解决任何问题。

那么如何在部分受信任的环境中从 WebForms(RDLC 报告)生成 PDF?

编辑:我在 VS 2008 中使用 C# 3.5。

My goal is to generate a PDF for display in a web page, either as aspx or with a generic handler. (This will link from a Silverlight page, but this is irrelevant to the problem.)

The problem is that LocalReport (Microsoft.Reporting.WebForms; Microsoft.ReportViewer.WebForms.dll) requires full trust, and our hosting server does not allow full trust. I am aware that ReportViewer has a remote mode that will allow it to run with partial trust, but for that I need a report server url which should probably have full trust as well, which does not solve anything.

So how do I generate PDFs from WebForms (RDLC reports) in a partially trusted environment?

EDIT: I am using C# 3.5 with VS 2008.

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

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

发布评论

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

评论(3

千仐 2024-10-16 21:00:43

您应该先咨询您的托管公司,看看他们的系统上是否安装了 PDF 创建库,然后使用它。

我还没有在中等信任度中测试自己,但有些人通过这个开源项目在中等信任度中取得了成功:
http://sourceforge.net/projects/itextsharp/

干杯,
Stefan

更新

private LocalReport CreateReport()
{
    LocalReport myReport = new LocalReport();
    myReport.ReportPath = "Report1.rdlc";

    // Insert parameters if needed
    ReportParameter myParam = new ReportParameter("MyParamName", "myParamValueAsString");

    myReport.SetParameters(new ReportParameter[] { myParam });

    return myReport;
}
You can call the function to create the PDF:



//Create new pdf file
Byte[] mybytes = CreateReport().Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings);

并且 mybytes 可以通过 Response 写出以供下载..

You should check with your hosting company whatever they have a PDF creation library installed on their system first and use that.

I have not tested my self in medium trust but some people have had success in Medium Trust with this Open Source project:
http://sourceforge.net/projects/itextsharp/

Cheers,
Stefan

Update

private LocalReport CreateReport()
{
    LocalReport myReport = new LocalReport();
    myReport.ReportPath = "Report1.rdlc";

    // Insert parameters if needed
    ReportParameter myParam = new ReportParameter("MyParamName", "myParamValueAsString");

    myReport.SetParameters(new ReportParameter[] { myParam });

    return myReport;
}
You can call the function to create the PDF:



//Create new pdf file
Byte[] mybytes = CreateReport().Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings);

And the mybytes can be written out with Response for download..

独留℉清风醉 2024-10-16 21:00:43

除非我得到更多答案来解决问题,否则这将是最好的解决方法:

我联系了托管服务器,他们有一个单独的服务器,允许访问 Microsoft.ReportViewer (可能运行完全信任),但需要额外付费。

Unless I get any more answers to resolve the issue, this will be the best workaround:

I contacted the hosting server, and they have a separate server which allows access to Microsoft.ReportViewer (probably running full trust), but at an additional fee.

七禾 2024-10-16 21:00:43

您在服务器上使用的是 .NET 4 还是以前的版本?我相信(基于 MSDN 上的此帮助页面: http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.localreport.executereportinsandboxappdomain.aspx),ReportViewer 控件始终在沙盒应用程序域中执行。但对于之前的版本(或者当您使用 LegacySecurityPolicy 时),您需要显式指定报表查看器应通过调用 LocalReport 对象上的 ExecuteReportInSandboxAppDomain 方法来执行此操作。我不确定,但这可能可以解决您的问题。

Are you using .NET 4 on the server, or a previous version? I believe (based upon this help page on MSDN: http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.localreport.executereportinsandboxappdomain.aspx) that the ReportViewer control always executes in the sandboxed application domain. For prior versions though (or when you are using LegacySecurityPolicy), you need to explicitly specify that the report viewer should do so by calling the ExecuteReportInSandboxAppDomain method on the LocalReport object. I don't know for sure, but this may solve your problem.

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