简体   繁体   English

在aspx中使用ashx上传文件会导致超时错误

[英]Upload file using ashx in aspx causes timeout error

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. 我有一个网站,我的用户可以将他们的文件上传到个人资料,但是我不希望使用直接链接下载文件,所以我使用的是ashx。

I upload the file in App_data using ashx. 我使用ashx将文件上传到App_data中。 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? 我该怎么办?

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). 使用现成的ASP.NET,您将无法上传大文件(大小为千兆字节),因为IIS可能会超时,或者您将超出大小限制(请maxRequestLengthmaxRequestLength设置,用于IIS)。

You have a few options: 您有几种选择:

  1. Custom HTTP module 自定义HTTP模块

    NeatUpload is a free option. NeatUpload是一个免费选项。

  2. Silverlight/Flash option Silverlight / Flash选项

    SWFUpload is a free option. SWFUpload是一个免费选项。

  3. Asynchronous chunking option 异步分块选项

    RadAsyncUpload - Telerik's ASP.NET AsyncUpload is a pay option, check website for pricing. RadAsyncUpload-Telerik的ASP.NET AsyncUpload是一种付费选项,请检查网站的价格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM