2014-02-12 64 views
0

我有一個經典的ASP應用程序,它允許用戶下載由第三方供應商提供的Excel文檔。以下是示例代碼。如果文檔大小大於4mb,則會出現「超出響應緩衝區限制」錯誤。經典的ASP IIS 6響應緩衝區限制超出

我做了一些研究,嘗試了不同的東西。只有在IIS中增加緩衝區限制解決了我的問題。但是我的系統團隊不願意對生產進行這種​​改變。

是否有替代解決方案? 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 

回答

0

您需要逐個推送內容,例如,按每塊1Mb計算。如果您的COM對象("Some.Object")不允許按塊讀取,則可以使用方法stream.Read(count)使用ADODB.Stream對象。

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 
+0

你能不能給我如何做到這一點的例子嗎? – user2543670

+0

太好了。謝謝。我會給這個鏡頭。 – user2543670