2013-04-04 47 views
1

我對它們加密後上傳在本地驅動器上的文件和我在web.config中最大上傳限制爲如何處理上傳中的「System.OutOfMemoryException」?

<httpRuntime maxRequestLength="2147483647" executionTimeout="1000"/> 

當文件大小爲greator然後20MB以下異常顯示

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception 

Stack Trace: 
[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.] 
System.IO.MemoryStream.set_Capacity(Int32 value) +93 
System.IO.MemoryStream.EnsureCapacity(Int32 value) +50 
System.IO.MemoryStream.WriteByte(Byte value) +130 
System.IO.BinaryWriter.Write(Byte value) +20 
System.Web.UI.SerializerBinaryWriter.WriteEncoded(Int32 value) +62 
System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +2081 

[ArgumentException: Error serializing value '644314' of type 'System.Int32.'] 
System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +3371 
System.Web.UI.ObjectStateFormatter.Serialize(Stream outputStream, Object stateGraph) +141 
System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph) +57 
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Serialize(Object state) +4 
System.Web.UI.Util.SerializeWithAssert(IStateFormatter formatter, Object stateGraph) +37 
System.Web.UI.HiddenFieldPageStatePersister.Save() +79 
System.Web.UI.Page.SavePageStateToPersistenceMedium(Object state) +108 
System.Web.UI.Page.SaveAllState() +315 
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2839 

什麼將是這種例外的原因,以及如何解決這個問題。

+0

看起來像你試圖讓你的文件在ViewState中,併發回客戶端..? – Lanorkin 2013-04-04 10:49:53

+0

我在上傳期間保存文檔字節在viewstate。對記憶有任何影響。 – mck 2013-04-04 10:52:51

回答

3

你不應該在ViewState中存儲文件。它會對性能造成非常不利的影響(因爲它會在每個後續請求中傳輸兩次)

您需要將文件存儲在臨時文件夾中,然後將文件路徑存儲在ViewState中,請記住您需要某種排序的清理例程,刪除(例如)一天的文件

相關問題