我收到以下错误:
System.Web.dll 中发生了“System.Web.HttpException”类型的第一次机会异常
附加信息:超出最大请求长度。
当我尝试上传 250 个大小为 98.kb 的 jpeg 时,总共大约 31 mb。现在我知道 fileuploader 默认情况下不允许超过 4mb 的文件,这是否意味着每个文件必须小于 4mb,或者每次上传尝试的总大小必须小于 4mb?
我用谷歌搜索了一个解决方案,并在我的网络配置中尝试了以下内容
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="524288000" />
</requestFiltering>
</security>
但我仍然遇到同样的错误!??
这是我的代码:
public partial class ReUpload : System.Web.UI.Page
{
HttpFileCollection uploads = HttpContext.Current.Request.Files;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session.Remove("paths");
ListBox1.Items.Clear();
Session.Add("paths",uploads);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try
{
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
string fn = System.IO.Path.GetFileName(hpf.FileName);
string SaveLocation = Server.MapPath("Uploaded") + "\\" + fn;
ListBox1.Items.Add(fn + " succsessfully uploaded");
hpf.SaveAs(SaveLocation);
}
}
}
catch (Exception ex)
{
// Handle your exception here
Response.Write("Error: " + ex.Message);
}
}
else if(ListBox1.Items.Count != 0)
{
ListBox1.Items.Clear();
HttpFileCollection hfc = (HttpFileCollection)Session["paths"];
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
string fn = System.IO.Path.GetFileName(hpf.FileName);
string SaveLocation = Server.MapPath("Uploaded") + "\\" + fn;
ListBox1.Items.Add(fn + " succsessfully uploaded");
hpf.SaveAs(SaveLocation);
}
}
}
else
{
Response.Write("Please select a file to upload.");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
if (FileUpload1.HasFile)
{
try
{
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
Session["paths"] = hfc;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
ListBox1.Items.Add(hpf.FileName);
}
}
//ViewState["count"] = ListBox1.Items.Count;
}
catch (Exception ex)
{
// Handle your exception here
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}
}
}
}