2010-11-17 45 views
14

我有通过POST接受二进制数据并读取字节数组的代码。对于大于200 Kb的文件,操作失败。我检查了我的系统管理员(我们正在运行IIS 7),看看我们的配置是否有限制,他说没有,并怀疑这是代码问题。有没有人在这里看到任何潜在的问题?这里是我的代码:Request.BinaryRead(Request.TotalBytes)为大文件抛出错误

Public Sub Initialize 
    If Request.TotalBytes > 0 Then 
    Dim binData 
     binData = Request.BinaryRead(Request.TotalBytes) ' This line fails' 
     getData binData 
    End If 
End Sub 


Private Sub getData(rawData) 
    Dim separator 
     separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1) 

    Dim lenSeparator 
     lenSeparator = LenB(separator) 

    Dim currentPos 
     currentPos = 1 
    Dim inStrByte 
     inStrByte = 1 
    Dim value, mValue 
    Dim tempValue 
     tempValue = "" 

    While inStrByte > 0 
     inStrByte = InStrB(currentPos, rawData, separator) 
     mValue = inStrByte - currentPos 

     If mValue > 1 Then 
     value = MidB(rawData, currentPos, mValue) 

     Dim begPos, endPos, midValue, nValue 
     Dim intDict 
      Set intDict = Server.CreateObject("Scripting.Dictionary") 

      begPos = 1 + InStrB(1, value, ChrB(34)) 
      endPos = InStrB(begPos + 1, value, ChrB(34)) 
      nValue = endPos 

     Dim nameN 
      nameN = MidB(value, begPos, endPos - begPos) 

     Dim nameValue, isValid 
      isValid = True 

      If InStrB(1, value, stringToByte("Content-Type")) > 1 Then 

      begPos = 1 + InStrB(endPos + 1, value, ChrB(34)) 
      endPos = InStrB(begPos + 1, value, ChrB(34)) 

      If endPos = 0 Then 
       endPos = begPos + 1 
       isValid = False 
      End If 

      midValue = MidB(value, begPos, endPos - begPos) 
       intDict.Add "FileName", trim(byteToString(midValue)) 

      begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:")) 
      endPos = InStrB(begPos, value, ChrB(13)) 

      midValue = MidB(value, begPos, endPos - begPos) 
       intDict.Add "ContentType", trim(byteToString(midValue)) 

      begPos = endPos + 4 
      endPos = LenB(value) 

      nameValue = MidB(value, begPos, ((endPos - begPos) - 1)) 
      Else 
      nameValue = trim(byteToString(MidB(value, nValue + 5))) 
      End If 

      If isValid = True Then 

      intDict.Add "Value", nameValue 
      intDict.Add "Name", nameN 

      dict.Add byteToString(nameN), intDict 
      End If 
     End If 

     currentPos = lenSeparator + inStrByte 
    Wend 
    End Sub 

这里是出现在日志中的错误:

Log Name:  Application  
Source:  Active Server Pages  
Date:   11/11/2010 2:15:35 PM  
Event ID:  5  
Task Category: None  
Level:   Error  
Keywords:  Classic  
User:   N/A  
Computer:  xxxxx.xxxxx.xxx  
Description:  
Error: File /path-to-file/loader.asp Line 36 Operation not Allowed. .  
Event Xml:  
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">  
    <System>  
    <Provider Name="Active Server Pages" />  
    <EventID Qualifiers="49152">5</EventID>  
    <Level>2</Level>  
    <Task>0</Task>  
    <Keywords>0x80000000000000</Keywords>  
    <TimeCreated SystemTime="2010-11-11T19:15:35.000Z" />  
    <EventRecordID>19323</EventRecordID>  
    <Channel>Application</Channel>  
    <Computer>PHSWEB524.partners.org</Computer>  
    <Security />  
    </System>  
    <EventData>  
    <Data>File /mghdev/loader.asp Line 36 Operation not Allowed. </Data>  
    </EventData>  
</Event> 

回答

2

如果你读了BinaryRead方法的规范,你将看到参数实际上是一个不折不扣的参数以及。 BinaryRead方法试图改变它不能做的Request.TotalBytes的值。 TotalBytes是只读的。

您可以通过将TotalBytes分配给变量并将其传入,从而轻松解决此问题。这是示例代码在MSDN文档中显示的内容。

如果BinaryRead读取不同数量的数据,则该变量将反映读取的大小。

+1

我经常使用Request.BinaryRead(Request.TotalBytes)没有问题。如果您将只读或常量传递给[out]参数,VBScript不会引发错误,它仅为参数即时创建临时存储。 – AnthonyWJones 2010-11-19 09:33:38

+0

我通过代码更改了myTotalBytes = Request.TotalBytes,然后binData = Request.BinaryRead(myTotalBytes),但仍然收到相同的错误。 – Adam 2010-11-29 14:20:31

+0

如果这是一个TotalBytes访问权限问题,它不会影响只有大于200k的文件。我认为安东尼的解决方案更现实。 – castle1971 2014-07-01 07:35:54

32

默认情况下,POST请求中实体大小的限制是200K,因此是您的错误。

您可以增加限制打开IIS管理器并将树导航到您的应用程序。双击主面板中的“ASP”图标。展开“限制”类别。修改“最大请求实体主体限制”为一个更大的值。

如果这是针对公共网站的,请注意您设置的限制,限制的目的是为了防止恶意的POST压倒站点。