在web.config文件的 <configuration> </configuration>
中添加<httpRuntime executionTimeout="90" maxRequestLength="100000" useFullyQualifiedRedirectUrl="false" />

解决方案 »

  1.   

    看服务器上的 machine.config ,里面设置的最大的Request量。要上传大文件,需要手工修改配置文件。
      

  2.   

    <configuration>
       <system.web>
          <httpRuntime 
             maxRequestLength="4000"
             useFullyQualifiedRedirectUrl="true"
             executionTimeout="45"
             versionHeader="1.1.4128"/>
       </system.web>
    </configuration>----------
    核心:maxRequestLength="4000"改大就可以了
      

  3.   

    web.config中最大长度为你需要的大小
      

  4.   

    在web.config中添加<httpRuntime maxRequestLength="10240">
    </httpRuntime>修改maxRequestLength的值即可
      

  5.   

    在web.config中添加<httpRuntime maxRequestLength="10240">
    </httpRuntime>修改maxRequestLength的值即可
      

  6.   

    While putting together a quick-and-dirty file upload page for one of our clients, I ran into a problem where, if the file was over the acceptable size (more on that in a moment), the user would simply get a "DNS" error, or some other horrid error that I had no control over.  The problem was that if the filesize limit was exceeded, my code didn't even run on the server.  It was as if the user never even hit the submit button, or so it seemed.Ok, fine.  As I usually do when I run into these kinds of baffling issues, I cranked my browser and hit the google site.  I searched and searched, and read about 30-40 different discussions, and finally came to the conclusion that nobody has figured this out yet, or at least they aint' talkin'.  That meant that I either had to figure it out for myself, or give up.  If you are a programmer, you already know which one I chose.The good news, I am proud to say, is that the problem is solved, and here is the solution.First, if you are reading this, there is a good chance you have run into this problem before, but just in case, you should know what I mean by the "filesize limit".  In .Net, there is a default limit on the size of any web request of about 4 megs.  This is defined in the machine.config file, and you should probably leave that alone.  If you need larger files, you can override the setting in your websites own web.config file by putting this tag inside the "system.web" section, like this:<httpRuntime maxRequestLength="8000" />That number (8000) is in kilobytes.  Keep that in mind because it will matter in a moment.  8000k is around 8 megs.  If, using that setting, you try to upload a file that is, say, 8001k, you will NOT get an error.  At least not in your code.  In fact, your code won't run at all.  The user, on the other hand, will get one of those pretty "Cannot find server or DNS Error" errors you get when you type in the name of a website that does not exist.  If that is ok with you, then there is no need to read on.  If not...The problem is that the "maxRequestLength" setting (whether the default in the machine.config or your own in the web.config) tells your application to absolutely refuse anything larger than the maxRequestLength size.  Because ASP.Net is doing what you told it to do, your code does not get "exposed" to this inappropriate file that you don't want.  The default setting (around 4 megs) is there to help avoid denial of service attacks.  This only works if you do NOT let the file get on your server, which means your server throws out the request altogether, leaving the user with a bad feeling about your programming skills.But wait, there is HOPE!There is a way to deal with this issue cleanly and even more accurately than the maxRequestLength setting does.  You still need that setting if you want to override the default and get larger files, but in addition to that, you need to add a little code to the "global.asax.vb" file, which is the codebehind file for the global.asax.Take a look at this code:     Sub Application_BeginRequest( _
            ByVal sender As Object, ByVal e As EventArgs)        ' Fires at the beginning of each request
            Dim i As Integer
            'this number is in bytes, NOT kilobytes!!
            Dim iMaxFileSize As Integer = 8000000 
            For i = 0 To Request.Files.Count - 1
                If Request.Files.Item(i).ContentLength > iMaxFileSize Then
                    Response.Redirect( _
                        "FileToBig.aspx?filesize=" & _
                        Request.Files.Item(i).ContentLength)
                    Exit For
                End If
            Next
        End SubThe "Application_BeginRequest" sub in the global.asax.vb file fires at the beginning of each request, BEFORE the data has been completely uploaded.  This sub has access to the headers, and can look at the properties of any uploaded files.  If a file is, in this example, larger than 8000 kilobytes (8000000 bytes), the user is redirected to your custom error page, along with a querystring containing the size of the file they tried to upload.  You could include the filename too, or anything else you want to tell them.  The important thing is that, upon redirecting the user, the server discards the input stream and you don't have a 300 meg file in memory on your server.There are a couple of interesting things to notice here.  First, you are looking at individual files.  If there are multiple file fields on the page, the user could still upload more than 8000k by uploading two 7000k files.  If you want to deal with that situation, you may want to use "Request.ContentLength" instead of looping through the files, like this:     Sub Application_BeginRequest( _
            ByVal sender As Object, ByVal e As EventArgs)        ' Fires at the beginning of each request
            Dim i As Integer
            'this number is in bytes, NOT kilobytes!!
            Dim iMaxFileSize As Integer = 8000000 
            If Request.ContentLength > iMaxFileSize Then
                Response.Redirect("RequestTooBig.aspx?size=" & _ 
                    Request.ContentLength )
            End If
       End SubThat code will take all of the uploaded files into consideration, and not allow any request that is larger than your limit.You may want to do a combination of both, and there are lots of variations on this, but I think you get the picture.  Don't forget that if you are allowing anything larger than the default total request size of 4 megs you will still need to alter your web.config to allow it, otherwise you will still show your user an ugly error.  Also remember that the web.config only deals with the overall size of the entire request, including text fields and anything else in your form.If you found this article useful (or not) we would really appreciate it if you would tell us about it using the link below.