Request.BinaryRead(Request.TotalBytes) 对大文件抛出错误 [英] Request.BinaryRead(Request.TotalBytes) throws error for large files

查看:24
本文介绍了Request.BinaryRead(Request.TotalBytes) 对大文件抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have code that accepts binary data via POST and reads in an array of bytes. For files larger than 200 Kb, the operation fails. I've checked with my sysadmin (we're running IIS 7) to see if there was a limit in our configuration and he says there is none, and suspects it is a problem with the code. Does anybody here see any potential problems? Here is my code:

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

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

Here is the error that appears in the logs:

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>

推荐答案

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

By default the limit for the entity size in a POST request is 200K, hence your error.

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

You can increase that limit open IIS Manager and navigate the tree to your application. Double click the "ASP" icon in the main panel. Expand the "Limits" category. Modify the "Maximum Requesting Entity Body Limit" to a larger value.

如果这是针对公共网站,请注意您设置的限制,限制的目的是防止恶意 POST 淹没网站.

If this is for a public web-site be careful as to the limit you set, the purpose of the limit is to prevent malicious POSTs overwhelming the site.

这篇关于Request.BinaryRead(Request.TotalBytes) 对大文件抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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