C#的BinaryWrite通过SSL [英] C# BinaryWrite over SSL

查看:262
本文介绍了C#的BinaryWrite通过SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想回与存储在MSSQL VARBINARY(MAX)领域的PDF客户端响应。响应工作在我的本地和over HTTP连接测试服务器,但在生产服务器通过HTTPS连接不起作用。我使用的只是一个简单的BinaryWrite(code以下)。

I am trying to respond back to a client with a PDF stored in a MSSQL varbinary(MAX) field. The response works on my localhost and a test server over http connection, but does not work on the production server over https connection. I am using just a simple BinaryWrite (code below).

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

    Response.ContentType = "application/pdf";
    Response.BinaryWrite(displayFile);

没什么特别的在这里。只要抓住二进制数据,设置内容类型,并写回客户端。有什么特别需要以这种方式进行回应,从而通过HTTPS办?

Nothing fancy here. Just grab the binary data, set the content type, and write back to client. Is there anything special that needs to be done in order to respond back over https in this way?

编辑:按不工作,我的意思是,我得到在浏览器中一个空白文档。杂技演员不加载到浏览器。

By doesn't work, I mean that I get a blank document in the browser. Acrobat does not load in browser.

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

I just noticed that this problem is only occurring in IE 7. The PDF loads correctly in Firefox 3. Our client uses IE 7 exclusively (better than IE 6 which I persuaded them upgrade from...lol).

编辑:试图添加标题内容处置,使文件的行为作为附件。浏览器没有根据与IE错误SSL装Internet Explorer无法从ProductionServer.net下载displayFile.aspx。 (code以下)

Tried to add the header "content-disposition" to make the file act as an attachment. Browser failed to loaded under SSL with the IE error "Internet Explorer cannot download displayFile.aspx from ProductionServer.net." (Code Below)

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

编辑:如果该文件被视为通过http在生产服务器上,浏览器显示的code为PDF喜欢它正在通过记事本查看。 (例如PDF%,1.4%âãÏÓ6 0 OBJ<> endobj外部参照6 33 ...等)

If the file is viewed over http on the Production Server, the browser displays the code for the PDF like it was being viewed through NotePad. (e.g. %PDF-1.4 %âãÏÓ 6 0 obj <> endobj xref 6 33 ...etc)

推荐答案

我勉强通过更换来解决这个问题。

I just managed to get around this by replacing

Response.Clear();

Response.ClearContent();
Response.ClearHeaders();

所以整个事情是这样的:

so the whole thing looks like:

byte[] downloadBytes = doc.GetData();
Response.ClearContent();
Response.ClearHeaders();

Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Length", downloadBytes.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=myFile.pdf");
Response.BinaryWrite(downloadBytes);
Response.Flush();
Response.End();

这篇关于C#的BinaryWrite通过SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆