Upload file using ashx in aspx causes timeout error

973 views Asked by At

I have a website that my users can upload their files to their profile, but i don't want the files downloaded using a direct link so I am using ashx.

I upload the file in App_data using ashx. Here is my code :

int CountFile = 0;
string filename = "";

string path = Server.MapPath("~") + "App_Data";
String[] validext = { ".pdf" ,".doc",".zip"};                   
string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName);

//int test = Array.IndexOf(validext, ext.ToLower());
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{              
    LblMessage.ForeColor = System.Drawing.Color.Red;
    LblMessage.Text = "پسوند فایل معتبر نیست";
    return;
}

ClsSendEmail objSendEmail=new ClsSendEmail();
string[] Infotmp=new string[12];
string res = ObjRegUser.UploadArticle(Session["UserSession"].ToString(), txtArticleSubject.Text, Value[DDLSubjectGroup.SelectedIndex].ToString());

 if (res!="-1")
 {
    FileUpload1.PostedFile.SaveAs(path + "\\" + res+ext);
    ObjRegUser.UpdateArticleLocation(int.Parse(res),res+ext);
    string Url = "~/Users/Default.aspx?Message=" + "فایل با موفقیت ارسال شد" + "&" + "State=True";
    // Infotmp=  ObjRegUser.SelectUserProfile(Session["UserSession"].ToString());
    //objSendEmail.SendEmail("تایید ارسال مقاله به همایش ملی سرب و روی ایران",objSendEmail.SuccessArticleUpload(Infotmp[1].ToString()+" "+Infotmp[2].ToString(),txtArticleSubject.Text),Infotmp[6]);

    Response.Redirect(Url);
 }
 else if (res == "-1")
 {
    string Url = "~/Users/Default.aspx?Message=" + "تعداد فایل ارسالی بیشتر از حد مجاز می باشد " + "&" + "State=False";
    Response.Redirect(Url);
 }     

But I have a big problem, when my users want to upload their files, (big file size,slow internet speed) the connection is reset and times out.

What should i do?

1

There are 1 answers

1
Karl Anderson On BEST ANSWER

With out-of-the-box ASP.NET, you are not going to be able to upload a file that is huge (gigabytes in size), because IIS will either timeout or you will exceed the size limitations (read: maxRequestLength setting for IIS).

You have a few options:

  1. Custom HTTP module

    NeatUpload is a free option.

  2. Silverlight/Flash option

    SWFUpload is a free option.

  3. Asynchronous chunking option

    RadAsyncUpload - Telerik's ASP.NET AsyncUpload is a pay option, check website for pricing.