柚子Nan--回归原点

Everything can be as easy as you like or as complex as you need.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ASP.NET中关于上传附件的大小设置问题

Posted on 2005-04-21 16:33  柚子Nan  阅读(11264)  评论(25编辑  收藏  举报

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;

}

大家有什么办法嘛?