相关疑难解决方法(0)

C#BinaryWrite over SSL

我正在尝试使用存储在MSSQL varbinary(MAX)字段中的PDF回复客户端.响应通过http连接在我的localhost和测试服务器上运行,但不能通过https连接在生产服务器上运行.我只使用一个简单的BinaryWrite(下面的代码).

    byte[] displayFile = DatabaseFiles.getPdfById(id);

    Response.ContentType = "application/pdf";
    Response.BinaryWrite(displayFile);
Run Code Online (Sandbox Code Playgroud)

没什么好看的.只需获取二进制数据,设置内容类型,然后写回客户端.为了以这种方式回复https,是否有任何特殊需要做的事情?

编辑:通过不起作用,我的意思是我在浏览器中得到一个空白文档.Acrobat不会在浏览器中加载.

编辑:我只是注意到这个问题只发生在IE 7中.在Firefox 3中正确加载PDF.我们的客户端专门使用IE 7(优于IE 6,我说服他们升级...大声笑).

编辑:尝试添加标题"content-disposition"以使文件充当附件.浏览器无法在SSL下加载IE错误"Internet Explorer无法从ProductionServer.net下载displayFile.aspx".(以下代码)

    byte[] displayFile = DatabaseFiles.getPdfById(id);
    Response.Clear();
    Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", fileName));
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(displayFile);
Run Code Online (Sandbox Code Playgroud)

编辑:如果在生产服务器上通过http查看文件,浏览器将显示PDF的代码,就像通过NotePad查看一样.(例如%PDF-1.4%â€6 0 obj <> endobj xref 6 33 ...等)

.net c# binary file

4
推荐指数
1
解决办法
6264
查看次数

标签 统计

.net ×1

binary ×1

c# ×1

file ×1