我希望限制文件上传的大小,但问题在于当上传大小超过限制时,我想提供一个弹出警告框,但实际上网页显示以下错误信息:
HTTP Error 404.13 - Not Found
请求筛选模块被配置为拒绝超过请求内容长度的请求。
这是我的代码
protected void Button1_Click(object sender, EventArgs e)
{
if (fuDocpath.HasFiles)
{
try
{
DateTime now = DateTime.Now;
lbldateStamp.Text = now.ToString("mm_dd_yyyy_hh_mm_ss");
//string foldername = lblsessionID.Text + "_" + lbldateStamp.Text;
string folderpath = (Server.MapPath("~/Uploaded_Files/") + lblsessionID.Text + "_" + lbldateStamp.Text + "/");
Directory.CreateDirectory(folderpath);
if (fuDocpath.PostedFile.ContentLength < 20970000)
{
try
{
foreach (HttpPostedFile files in fuDocpath.PostedFiles)
{
string filename = Path.GetFileName(files.FileName);
string folderpath1 = folderpath + "/";
fuDocpath.SaveAs(folderpath1 + filename);
lblName.Text = lblName.Text + "|" + filename;
lblerror.Text = string.Empty;
}
}
catch (Exception eex)
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + eex.Message + "')", true);
}
}
}
catch (Exception ex)
{
lblerror.Text = "File couldn't be uploaded." + ex.Message;
lblName.Text = string.Empty;
}
}
}