Asp.net:托管后无法上传较大的文件 [英] Asp.net : unable to upload larger file after hosting

查看:50
本文介绍了Asp.net:托管后无法上传较大的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我无法使用以下编码上传较大的文件..我尝试使用20mb文件,并且上传时没有任何问题.但是当我尝试上传80mb文件时,上传失败..虽然它没有返回任何错误..即使我正在成功上传"消息,但实际上没有任何上传..但是当我在本地运行该应用程序时,也就是说,在asp.net服务器上,我甚至可以上传90mb的文件..因此,问题仅在托管站点之后才开始..我是否必须为此添加ant服务器端编码?..我没有关于这个的想法..请帮助我...

hi ,

I''m not able to upload larger file using the below codings..i tried with 20mb file and its uploaded without any problem. but when i tried to upload 80mb file , the upload fails.. it doesn''t returns any error though.. even i''m getting "successfully uploaded" message but nothing was uploaded actually.. But when i run the application locally , that is , on asp.net server , i''m able to upload even 90mb file.. so the problem starts only after hosting the site.. am i have to add ant server side coding for this?.. i have no idea about this.. pls help me...

HttpFileCollection uploadFilCol = Request.Files;
                try
                {
                    for (int i = 0; i < uploadFilCol.Count; i++) //uploadFilCol.Count
                    {
                        HttpPostedFile file = uploadFilCol[i];
                        string fileExt = Path.GetExtension(file.FileName).ToLower();
                        string fileName = Path.GetFileName(file.FileName);
                      
                        if (file.ContentLength > 0)
                        {

                            if (fileName != string.Empty)
                            {
                               
                                createdir(ftpaddress + Session["userid"].ToString(), user, pass);
                                try
                                {
                                   
                                    if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png" || fileExt == ".jpeg" || fileExt == ".rar" || fileExt == ".zip" || fileExt == ".7z")
                                    {
                                       
                                        FtpWebRequest uploadRequest = (FtpWebRequest)FtpWebRequest.Create(ftpaddress + Session["userid"].ToString() + @"/" + fileName);
                                        Stream requestStream = null;
                                        FtpWebResponse uploadResponse = null;
                                        try
                                        {
                                            Thread.Sleep(20);
                                            uploadRequest.Credentials = new NetworkCredential(user, pass);
                                            uploadRequest.KeepAlive = false;
                                           
                                            uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;
                                            uploadRequest.UseBinary = true;
                                            uploadRequest.Timeout = 10000000;
                                            byte[] buffer = null;
                                            uploadRequest.Proxy = null;
                                            requestStream = uploadRequest.GetRequestStream();
                                            long bytesToRead = file.ContentLength;
                                            int bytesRead = 0;

                                            while (bytesRead < bytesToRead)
                                            {
                                                buffer = new byte[file.ContentLength];

                                                bytesRead += file.InputStream.Read(buffer, 0, buffer.Length);
                                                if (bytesRead == 0)
                                                    break;

                                                requestStream.Write(buffer, 0, bytesRead);
                                              
                                            }


                                            requestStream.Close();
                                            uploadResponse = (FtpWebResponse)uploadRequest.GetResponse();
                                           
                                        }
                                        catch (UriFormatException ex)
                                        {
                                            lbl_error.Text = ex.Message;
                                        }
                                        catch (IOException ex)
                                        {
                                            lbl_error.Text = ex.Message;
                                        }
                                        catch (WebException ex)
                                        {
                                            lbl_error.Text = ex.Message;
                                        }
                                        finally
                                        {
                                            if (uploadResponse != null)
                                                uploadResponse.Close();
                                         
                                            if (requestStream != null)
                                                requestStream.Close();
                                        }
      
                                        this.ShowMessage("" + fileName + " Uploaded ", i);

                                    }
                                    else
                                    {
                                        this.ShowMessage(" <font color=red> This is not a Picture File</font/>", i);
                                    }
                                    //}
                                }
                                catch (Exception ex)
                                {
                                    this.ShowMessage("<font color=red> " + fileName + " Not Uploaded <font>", i);
                                }
                            }
                           
                        }
                        else
                        {
                            this.ShowMessage("<font color=red> " + fileName + " File size not more than 6MB</font>", i);
                        }
                      
                    }
                   

                }
               
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("default.aspx");
        }


    }

:((<
谢谢..

:((

Thanks..

推荐答案

听起来像您需要在Web.config中添加以下内容:

Sounds like you need to add the following to your Web.config:

<system.web>
    <httpRuntime maxRequestLength="2097151" />
</system.web>



此设置限制了您可以上传的文件的大小.默认设置为4096.如果您上传的所有文件都是小于4MB的小文件,则很好.我在这里将其设置为2097151-最大值.太高了.除非您有确实非常充分的理由这样做,而且确实确实需要上传2个演出文件,否则请不要随意设置.



This is the setting that restricts the size of files you can upload. The default setting is 4096. Fine if all you ever upload are small files of less than 4MB. I have set it here to 2097151 - the maximum. That is insanely high. Don''t leave it at that unless you have a really, really good reason to do so and really, really need to upload 2 gig files.


您好,亲爱的...
我认为此问题与主机无关,而是设置(web.config)文件
在system.web属性中添加此属性以设置最大上传文件大小10 mb(80mb = 80 * 1024 kb)
hello dear...
I think that this problem is not related to host, but settings (web.config) file
add this attributes in system.web attributes to set max upload file size 10 mb (80mb=80*1024 kb)
<httpRuntime maxRequestLength="10240" executionTimeout="3600"/>


这篇关于Asp.net:托管后无法上传较大的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆