我创建了一个带有 2 个页面的空 ASP.NET 应用程序,Default.aspx 和 Action.aspx(请参见下文)。运行时,我选择了一个 200k 的 .bmp 文件并点击保存。然后我收到“无法访问已关闭的文件”错误,但仅当我的源文件高于 55k 左右时。是什么赋予了?谢谢
默认.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="attachmentFileUpload" Width="300px" runat="server" />
<asp:Button ID="saveButton" runat="server" Text="Save" OnClick="saveButton_Click" />
</div>
</form>
</body>
</html>
默认.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class Simple : System.Web.UI.Page
{
protected void saveButton_Click(object sender, EventArgs e)
{
Session["AttachmentFileUpload"] = attachmentFileUpload;
Response.Redirect("Action.aspx");
}
}
}
动作.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Action.aspx.cs" Inherits="WebApplication1.Action" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
动作.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class Action : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FileUpload tempFileUpload = (FileUpload)Session["AttachmentFileUpload"];
tempFileUpload.PostedFile.SaveAs(@"C:\Temp\MyUpload.bmp");
}
}
}