Posted on 2005-04-21 16:33
柚子Nan 阅读(6432)
评论(25) 编辑 收藏 所属分类:
[技术.Net]
Asp.net中,上传文件的默认大小是4096 KB,也就是4M,不过你可以在Web.config中更改这个数据
<httpRuntime maxRequestLength="10240"
useFullyQualifiedRedirectUrl="true"
executionTimeout="100"/>
那么此时就是10M的文件,当然你也可以把它修改的更大,但是不管改成多大都会有个极限,如果用户上传的文件比这个值大,就会出现程序Catch不到的异常,因为这个是在运行时才能够监测,如下的错误:
|
Action canceled |
|
|
Internet Explorer was unable to link to the Web page you requested. The page might be temporarily unavailable. |
|
Please try the following:
- Click the Refresh button, or try again later.
- If you have visited this page previously and you want to view what has been stored on your computer, click File, and then click Work Offline.
- For information about offline browsing with Internet Explorer, click the Help menu, and then click Contents and Index.
|
虽然你在代码中控制了大小,不过程序在运行到这里之前已经崩溃了
// Attachment size is too larger
if(PersonPhoto.PostedFile.ContentLength > 10240)
{
this.lblError.Text = "The file you selected is larger than 10MB";
this.lblError.Visible = true;
return;
}
大家有什么办法嘛?