简体   繁体   English

超出了经典ASP IIS 6响应缓冲区的限制

[英]Classic ASP IIS 6 Response buffer limit exceeded

I have a Classic ASP application which allows users to download excel documents provided by a 3rd party vendor. 我有一个Classic ASP应用程序,允许用户下载第三方供应商提供的excel文档。 Below is sample code. 下面是示例代码。 If the document size is greater than 4mb, I get an error "Response buffer limit exceeded". 如果文档大小大于4mb,则会出现错误“超出了响应缓冲区限制”。

I did some research and tried different things. 我做了一些研究,尝试了不同的方法。 Only increasing the buffer limit in IIS resolved my issue. 仅增加IIS中的缓冲区限制解决了我的问题。 But my systems team is reluctant to make this change on production. 但是我的系统团队不愿意在生产中进行此更改。

Is there an alternate solution? 有替代解决方案吗? Is there a solution available in ASP.Net? ASP.Net中是否有可用的解决方案?

    set objDoc = Server.createobject("Some.Object")
    objDoc.DocId doc_id
    bin_obj = objDoc.Binary
    set objDoc = Nothing

    Response.buffer = TRUE
    Response.ContentType = "application/msexcel"
    Response.AddHeader "Cache-Control", "public"
    Response.AddHeader "Pragma", "public"   
    Response.AddHeader "Content-Disposition", "attachment;filename=test.xls"
    Response.BinaryWrite bin_obj
    Response.Flush
    Response.End

You need push content part by part, ex. 您需要部分地推送内容,例如。 by 1Mb per block. 每块减少1Mb。 If your COM object ( "Some.Object" ) dosn't allow read by block, you can make it using ADODB.Stream object with method stream.Read(count) . 如果您的COM对象( "Some.Object" )不允许按块读取,则可以使用ADODB.Stream对象以及stream.Read(count)方法来进行读取。

UPDATE: 更新:

Option Explicit

Dim streamS, streamB

Set streamS = Server.CreateObject("ADODB.Stream")
streamS.Type = 1 'Binary stream
streamS.Open
streamS.LoadFromFile Server.MapPath("/Nissan_Qashqai_IDTR.rar")

Set streamB = Server.CreateObject("ADODB.Stream")
streamB.Type = 1
streamB.Open

Dim blockSize
blockSize = 1024 ' block size is 1 KB

Response.AddHeader "Content-Disposition", "attachment;filename=MyTestBinryFile.bin"
Response.AddHeader "Content-Length", streamS.Size
Response.ContentType = "application/octet-stream"

Dim i
For i = 0 To streamS.Size - 1 Step blockSize
    streamB.Position = 0
    streamS.CopyTo streamB, blockSize
    streamB.Position = 0
    Response.BinaryWrite(streamB.Read)
    Response.Flush
Next

streamS.Close
Set streamS = Nothing

streamB.Close
Set streamB = Nothing

Response.Flush

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM