0

最近,我们将 SSL 添加到我支持的应用程序中,它破坏了一个“打印”按钮,出现与此处描述的问题类似的问题。

如果没有 SSL,该按钮将生成带有打开和保存提示的 PDF 报告。实施 SSL 并且我们对 MasterPage HTTP Cacheability 进行了更改后,“打印”按钮再次起作用。

我们的母版页在 Page_Load 中有以下代码:

Protected void Page_Load(object sender, EventArgs e) {
    Response.Buffer = true;
    Response.ExpiresAbsolute = DateTime.Now;
    Response.Expires = 0;
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
}

并将其更改/实现为:

Protected void Page_Load(object sender, EventArgs e) {
    Response.Buffer = true;
    Response.Expires = -1;
    Response.Cache.SetNoStore();
}

打印按钮 Click 事件的代码如下:

protected void btnPrint_Click(object sender, EventArgs e) {
    try {
        ClearMessage();

        BusinessObject _obj = GetBusinessObject();

        Id = _obj.BusinessObjectId;
        string strId = Id.ToString();
        Warning[] warnings;
        string[] streamIds;
        string encoding = string.Empty;
        string mimetype = string.Empty;
        string extension = string.Empty;

        ReportViewer viewer = new ReportViewer() {
            ProcessingMode = ProcessingMode.Remote
        };
        viewer.ServerReport.ReportPath = "/ReportPath/ReportFile";

        ReportParameterCollection objParams = new ReportParameterCollection();
        objParams.Add(new ReportParameter("ObjId", strId));

        viewer.ServerReport.SetParameters(objParams);

        byte[] bytes = viewer.ServerReport.Render("PDF", null, out mimetype, out encoding, out extension, out streamIds, out warnings);

        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = mimetype;
        Response.AddHeader("content-disposition", "attachment; filename=" + GetBusinessObject().ObjNumber + " Object Summary." + extension);
        Response.BinaryWrite(bytes);
        Response.End();
    }
    catch (Exception ex) {
        ClearMessage();
        ErrorEmail("AppError", "btnPrint_Click", ex);
    }
}

我认为一切都很好,但看起来它可能会导致更多问题,因为现在我有报告称页面之间显示了不正确的数据(来自一条记录的信息显示为另一条记录)。

可缓存性更改是实现 SSL 时代码中唯一发生的更改,我们之前没有任何关于这种情况的报告(该应用程序已经运行了一年多)。此外,我让我的后备程序员恢复生产分支代码中的更改,发布到我们的登台服务器,并尝试复制问题......他们做不到。

更新

我对站点范围的 web.config 进行了以下更改,问题似乎已经消失。谁能解释为什么这有效但代码没有?

<system.webServer>
    <staticContent>
        <clientCache cacheControlMode="DisableCache" />
    </staticContent>
<system.webServer>

更新

设置 <clientCache cacheControlMode="DisableCache" />没有解决问题,我们仍然间歇性地遇到问题。将接受的答案视为有效的解决方案。

4

1 回答 1

0

所以事实证明,问题实际上在于 SSL 证书安装不正确。基本设置是我们有一个负载平衡器和终止于 2 个 Web 服务器的 SSL 证书。

显示/保存了不正确的值,因为负载均衡器无法读取 cookie(因为它已加密)以确定要定向到哪个服务器,并且由于我们使用会话变量,它不会正确清除会话变量。

我们的权宜之计是将路由决策切换为基于 IP。正如您可以想象的那样,这会导致一个防火墙后面的所有用户都指向同一台服务器,从而破坏了负载平衡器的目的。

我们的永久解决方案是在负载均衡器上放置第三个 SSL 证书,解密 cookie 以确定要定向到哪个服务器,再次加密数据,然后将其发送到服务器。

希望这可以帮助遇到同样问题的其他人。

于 2013-04-25T18:25:33.540 回答