gpt4 book ai didi

c# - asp.net限制上传文件的大小

转载 作者:太空狗 更新时间:2023-10-30 01:04:09 25 4
gpt4 key购买 nike

我想将上传的文件大小限制在一定范围内。但是,这里的问题是我想在超过上传大小时提供弹出警报。但是,这里的网页反而显示如下错误

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;
}
}
}

最佳答案

看看这个 - How to increase the max upload file size in ASP.NET?

您可以在 web.config 中更改最大请求大小 - 默认为 4Mb

关于c# - asp.net限制上传文件的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24567093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com