受保护文件夹中的外部图像不会显示在子报表 RDLC

问题描述

我在公司目录中有几个外部图像,需要在 RDLC 报告(带有多个子报告)中显示并导出为 PDF。多亏了 an answer by John,从服务器端测试时,外部图像现在可以正确显示,但在从实时站点加载时不能。这是因为存储这些图像的文件夹上的 Windows Security 设置所致。

以前,我们会将存储在 SQL Server 表中的图像数据通过 aspx.cs 文件汇集到子报表中。现在我们已经开始在外部存储图像,需要像这样处理图像:

ALTER PROCEDURE [dbo].[getPicture] @key int
AS
BEGIN
    SELECT picID,CONCAT( N'\\path\to\file\',CONVERT(nvarchar(max),picID),'.jpg'
                 ) AS [Picture]
    FROM tblImageData
    WHERE key = @key
END
protected void Page_Load(object sender,EventArgs e)
{
    LocalReport localReport = new LocalReport();
    localReport.EnableExternalImages = true;
    localReport.ReportPath = Server.MapPath("~/Report.rdlc");
    localReport.SubreportProcessing +=
        new SubreportProcessingEventHandler(subSupply);
    localReport.Refresh();
    …
    //Render the report
    renderedBytes = localReport.Render(…);
    Response.Clear();
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(renderedBytes);
    Response.End();
}
public void subSupply(object sender,SubreportProcessingEventArgs e)
{
    int keyNumber = 1;
    sc.Open();
    DataSet dsSub = new DataSet();
    SqlDataAdapter sda = new SqlDataAdapter("getPicture",sc);
    sda.SelectCommand.CommandType = CommandType.StoredProcedure;
    sda.SelectCommand.Parameters.AddWithValue("@key",keyNumber.ToString());
    sda.Fill(dsSub,"ds291");
    sc.Close();
    e.DataSources.Add(new ReportDataSource("DataSet1",dtSub));
}

但如果没有适当的身份验证,图像将无法正确加载。目前网站上还有其他地方通过模拟经过身份验证的用户将图像加载到页面中,但这些位置不需要加载到 RDLC 报告中——因此图像在服务器端和客户端都正确显示。

我想知道是否有办法让经过身份验证的用户在加载 RDLC 子报表时提取图像数据——并在子报表的图像设置为“外部”时执行此操作。我的替代方法是通过单独的 DataSet OR 将所有图像的字节直接加载到子报告中,以从 getPicture SQL 过程中获取图像数据并将其收集回来进入子报表。我对前一个解决方案没有任何运气,而后者是我真的不想做的事情。

任何帮助将不胜感激!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...