Classic ASP IIS 6 Response buffer limit exceeded

2019-08-20 14:42发布

问题:

I have a Classic ASP application which allows users to download excel documents provided by a 3rd party vendor. Below is sample code. If the document size is greater than 4mb, I get an error "Response buffer limit exceeded".

I did some research and tried different things. Only increasing the buffer limit in IIS resolved my issue. 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?

    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

回答1:

You need push content part by part, ex. by 1Mb per block. 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).

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