Được gửi bởi
dq_ninh
Dưới đây là chú thích của FileUpload control trên mạng của MSDN.
One way to guard against denial of service attacks is to limit the size of the files that can be uploaded by using the FileUpload control. You should set a size limit that is appropriate for the types of files that you expect to be uploaded. The default size limit is 4096 kilobytes (KB), or 4 megabytes (MB). You can allow larger files to be uploaded by setting the maxRequestLength attribute of the httpRuntime element. To increase the maximum allowable file size for the entire application, set the maxRequestLength attribute in the Web.config file. To increase the maximum allowable file size for a specified page, set the maxRequestLength attribute inside the location element in Web.config. For an example, see location Element (ASP.NET Settings Schema).
When uploading large files, a user might also receive the following error message:
aspnet_wp.exe (PID: 1520) was recycled because memory consumption exceeded 460 MB (60 percent of available RAM).
Theo như trên, bạn phải thay đổi mức tối đa qua maxRequestLength. Nhưng tôi xin có một điều khuyến cáo: Hai điều quan trọng nhất của chuyển giao tư liệu qua hệ thống mạng/kết nối là 1) an-toàn 2) khắc phục và hồi phục khi bị lỗi.
Bạn có thể đễ dàng cho lập trình của bạn upload 100MB tư liệu. Nhưng chuyện gì sẽ xảy ra nếu người xử dụng đã tốn hết 2 tiếng đồng hồ, upload được 70% của 100MB file, sau đó bị rớt mạng? Họ phải trở lại để upload từ đầu chăng? Chuyện gì sẽ xảy ra nếu một tay hacker nào đó tiếp tục upload 100MB từ 100 pages khác nhau, chỉ với mục đích là quấy rối cho máy chủ tiếp tục hoạt động không ngừng? Đây chính là lý do tại sao Microft cho FileUpload mức tối đa là 4MB.
Thành thử ra, tăng mức tối đa từ 4MB lên 10MB, hoặc 100MB tuyệt đối, tuyệt đối, và tuyệt đối không phải là một phương án xử lý hữu hiệu.
Bookmarks