关于 ASP.NET2.0 FILEUPLOAD 上传文件大小设置问题
经过实践证明,即使是在实际应用中设置了限制文件大小的代码,但如果上传文件过大,
即超出系统默认,IE 还是会死机!解决的方法是:
- 首先在 WEB CONFIG 中,如下进行设置(KB 为单位,注意与代码中运用之区别);
- 其次,在代码中设置判断上传文件大小的方法。
注:以下 CODE 经过反复调试成功!
/* web.config 中的设置:
<!-- Set for Max_Request_Length in web.config -->
<httpRuntime maxRequestLength="10240" executionTimeout="2400"></httpRuntime>
<!-- Set for Max_Request_Length in web.config -->
</system.web>
*/
/* 判断上传文件大小的方法:
public static bool CheckUploadFileSize(int flag, int size)
{
if (flag == 1)
{
if (size < 2048000)
{
return true;
}
else
{
return false;
}
}
else
{
if (size < 5120000)
{
return true;
}
else
{
return false;
}
}
}
*/
关键点:代码中设置的上限,一定要小于在 web.config 中设置的上限!