/
UploadControlMemory.aspx.cs
34 lines (28 loc) · 1.2 KB
/
UploadControlMemory.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.IO;
using DevExpress.Web;
namespace SecurityBestPractices.UploadingFiles {
public partial class UploadControlMemory : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
void DoProcessing(byte[] contenBytes) {
System.Threading.Thread.Sleep(60000); // Delay to emulate processig time
}
void DoProcessing(Stream stream) {
System.Threading.Thread.Sleep(60000); // Delay to emulate processig time
}
protected void uploadControl_FilesUploadComplete(object sender, DevExpress.Web.FilesUploadCompleteEventArgs e) {
for(int i = 0; i < uploadControl.UploadedFiles.Length; i++) {
UploadedFile file = uploadControl.UploadedFiles[i];
if(file.IsValid) {
// Bad approach - possible Denial of Service
// DoProcessing(file.FileBytes);
// Good approach - use stream for large files
using(var stream = file.FileContent) {
DoProcessing(stream);
}
}
}
}
}
}