我的错误是Maximum request length exceeded.
我希望文件上传必须小于2MB。请帮助我修复下面的代码,谢谢
我的控制器:
public ActionResult Index()
{
var path = "~/Images/upload/";
if (Request.Files["UpFile"] != null && Request.Files["UpFile"].ContentLength < 2048)
{
var upload = Request.Files["UpFile"];
upload.SaveAs(Server.MapPath(path + upload.FileName));
}
else
{
ModelState.AddModelError("", "The size of file too big");
}
return View();
}
尝试管理最大请求长度,以将错误减少到最小:超过最大请求长度
我认为,即使您具有全局异常处理程序,在上载文件时使用try..catch也是一个好习惯。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句