Asp classic 对于大型文件,Request.BinaryRead(Request.TotalBytes)抛出错误
我的代码通过POST接受二进制数据,并读取字节数组。对于大于200 Kb的文件,操作将失败。我已经和我的系统管理员(我们正在运行IIS 7)进行了检查,看看我们的配置是否有限制,他说没有,并怀疑这是代码的问题。这里有人看到任何潜在的问题吗?这是我的密码:Asp classic 对于大型文件,Request.BinaryRead(Request.TotalBytes)抛出错误,asp-classic,vbscript,Asp Classic,Vbscript,我的代码通过POST接受二进制数据,并读取字节数组。对于大于200 Kb的文件,操作将失败。我已经和我的系统管理员(我们正在运行IIS 7)进行了检查,看看我们的配置是否有限制,他说没有,并怀疑这是代码的问题。这里有人看到任何潜在的问题吗?这是我的密码: Public Sub Initialize If Request.TotalBytes > 0 Then Dim binData binData = Request.BinaryRead(Request.Total
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>
日志名称:应用程序
来源:活动服务器页面
日期:2010年11月11日下午2:15:35
活动编号:5
任务类别:无
级别:错误
关键词:经典
用户:不适用
计算机:xxxxx.xxxxx.xxx
说明:
错误:不允许执行文件/loader.asp第36行的文件/路径操作。
事件Xml:
5.
2.
0
0x8000000000000
19323
应用
PHSWEB524.partners.org
不允许文件/mghdev/loader.asp第36行操作。
如果阅读BinaryRead方法的规范,您将看到该参数实际上也是一个out参数。BinaryRead方法正在尝试更改Request.TotalBytes的值,但无法更改该值。TotalBytes是只读的
您可以通过将TotalBytes分配给变量并将其传入来轻松解决此问题。这是MSDN文档中的示例代码
如果BinaryRead读取了不同数量的数据,则变量将反映读取的大小。默认情况下,POST请求中实体大小的限制为200K,因此会出现错误 您可以增加该限制,打开IIS管理器并将树导航到您的应用程序。双击主面板中的“ASP”图标。展开“限制”类别。将“最大请求实体实体限制”修改为更大的值
如果这是针对公共网站的,请小心设置的限制,限制的目的是防止恶意帖子淹没网站。IIS中的“限制属性”部分需要两个设置 1-最大请求实体正文限制(请不要以字节为单位)。您必须根据最大文件大小(例如-40MB(40000000字节))设置该值
2) -脚本超时。它的默认值是“00:01:30:90秒。根据代码运行所需的时间增加它。我将它设置为5分钟,它就解决了问题。我经常使用Request.binarydead(Request.TotalBytes),没有问题。如果将只读或常量传递给[out],VBScript将不会抛出错误参数,它只是动态地为参数创建临时存储。我通过代码更改为读取myTotalBytes=Request.TotalBytes,然后是binData=Request.BinaryRead(myTotalBytes),但我仍然得到相同的错误。如果这是TotalBytes访问权限的问题,它不会只影响大于200k的文件。我认为Anthony的解决方案更现实。