使用asp:FileUpload的System.OutOfMemoryException

时间:2014-04-29 17:28:29

标签: c# asp.net file-upload out-of-memory

我有一个内部有FileUpload控件的ASP.NET页面。 当我尝试上传第三个文件时,我得到了:

的System.OutOfMemoryException    在System.Convert.FromBase64String(String s)    在System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)    at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)    在System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter,String serializedState)    在System.Web.UI.HiddenFieldPageStatePersister.Load()

这是我的代码:

<td style="width: 60%; height: 67px; vertical-align: top">
    <div class="fileinputs" id="div2" style="left: 0px; top: 0px; width: 100%; vertical-align: middle">
        <div id="div3" class="fakefile" style="left: 0px; top: 0px; vertical-align: middle">
            <asp:TextBox ID="txtFileUpload" runat="server" Width="265px" CssClass="borde-form"
                Height="15px" ValidationGroup="docs" />
            <img name="imgExaminar" alt="Examinar" src="../../Images/botExaminar.gif" style="cursor: hand;
                width: 81px; height: 20px; vertical-align: middle" />
        </div>
        <asp:FileUpload EnableViewState="true" ID="fileUpload" runat="server" Width="368px"
            Height="19px" CssClass="hidden" />
    </div>
    <asp:CustomValidator ID="cvattachment" runat="server" OnServerValidate="cvattachment_ServerValidate"
        ControlToValidate="fileUpload" ErrorMessage="Existe un archivo con el mismo nombre"
        Font-Bold="False" Font-Names="Arial" Font-Size="X-Small" ValidationGroup="docs"></asp:CustomValidator>
</td>
<td style="width: 30%; height: 67px; vertical-align: top">
    <asp:ImageButton ID="imgAdjuntar" runat="server" ImageUrl="~/Images/botAdjuntar.GIF"
        OnClick="imgAdjuntar_Click" ValidationGroup="docs" Height="20px" Width="66px"></asp:ImageButton>
</td>

当我点击我的imgAdjuntar时,我收到错误,但永远不会调用imgAdjuntar_Click方法,而是触发Global.asax上的Application_Error。 另外,我的断点都没有进入,错误发生在到达应用程序代码之前。

也许控制是失败的控制? 我该怎么办?

谢谢!

1 个答案:

答案 0 :(得分:3)

确保您没有在ViewState中存储文件。

此外,尝试禁用整个页面的ViewState。

检查以下步骤,这可能会有所帮助:

How do i handle 'System.OutOfMemoryException' in uploading?

Exception of type 'System.OutOfMemoryException' was thrown