Uploading large files (40MB+) with ASP.Net

TheKyle
TheKyle used Ask the Experts™
on
I'm building a CMS that will allow the users to upload large files for downloading from their website.  I have the upload page working, but anytime I try to upload something larger than about 15-20MB, I get the following error...

===========================================
HTTP Error 404.13 - Not Found
Description: The request filtering module is configured to deny a request that exceeds the request content length.
Error Code: 0x00000000
Notification: BeginRequest
Module: RequestFilteringModule
Requested URL: http://localhost:80/xxxxx/files.aspx?ID=12
Physical Path: c:\inetpub\wwwroot\xxxxx\files.aspx
Logon User: Not yet determined
Logon Method: Not yet determined
Handler: PageHandlerFactory-ISAPI-2.0
Most likely causes:
    * Request filtering is configured on the Web server to deny the request because the content length exceeds the configured value.
What you can try:
    * Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting in the applicationhost.config or web.config file.
More Information... This is a security feature. Do not change this feature unless the scope of the change is fully understood. You can configure the IIS 7.0 server to reject requests whose content length is greater than a specified value. If the request's content length is greater than the configured length, this error is returned. If the content length requires an increase, modify the configuration/system.webServer/security/requestFiltering/requestLimits@maxAllowedContentLength setting.
Server Version Information: Internet Information Services 7.0.
===========================================

I am using IIS 7 on a Windows Vista machine.  I'm uploading using the ASP File Upload control, and I'm saving the file using the FileUpload.SaveAs(filename as string) function.  It works beautifully for files smaller than 15-20MB.

I've tried changing several things in my web.config and in my applicationHost.config file, but nothing has allowed me to upload anything larger than about 20MB.

Here are the applicable lines from my web.config...

===========================================
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
...
    <system.web>
        <httpRuntime executionTimeout="100000" maxRequestLength="2097151" />
...
    </system.web>
...
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="2097151" />
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>
===========================================

And here are the lines from my applicationHost.config...

===========================================
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <configSections>
...
        <sectionGroup name="system.webServer">
...
            <sectionGroup name="security">
...
                <section name="requestFiltering" overrideModeDefault="Allow" />
...
            </sectionGroup>
...
===========================================


Thanks for any help you can give me.  Please let me know if you need any more details.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I've actually already tried that solution.... As you can see in my code above, I have the "maxAllowedContentLength" in my web.config file.  And I have the "requestFiltering" override set to Allow in my applicationHost.config file.

I tried "changing" the machine.config file like your link says, but none of these elements exist in that file.  Also, every time I tried to add those elements to that file, I just got more errors telling me that they don't belong there.

Plus, the Microsoft KnowledgeBase article that is mentioned on that page only applies to .Net 1.0 and 1.1.  I'm using 2.0.

It may also help to know that I get the error immediately.  There is no timeout issue.  I click the button to upload, and if the file is too big, I immediately see the error page.

Thanks!
ok take a look at this
http://support.microsoft.com/kb/323245

try adding this to your machine.config, and adjust the maxrequestlength accordingly

<httpRuntime
executionTimeout="90"
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

The Machine.config file is located in the \System Root\Microsoft.NET\Framework\Version Number\Config folder.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Author

Commented:
@RedKelvin:
That's pretty much what I already have in my web.config.  The way I understand it, the machine.config controls all of the .Net application on the machine while the web.config controls only the specific website.  Either way, I tried putting the "httpRuntime" in both files with the same result.

Also, the Microsoft KnowledgeBase article that you referred to only applies to ASP.Net 1.0 and 1.1.

@Aurora27:
I'll see if I can somehow modify that solution to work for me, but as it is, it appears to be written in Classic ASP (3.0).  If you have some ASP.Net 2.0 code that I can look at, I would greatly appreciate it.  Otherwise, I'm going to have to take some time to port the Classic ASP code over.

Thanks to both of you for your time!
Commented:
http://www.123aspx.com/redir.aspx?res=36710

Iam testing this code now. :) Hope it works for you.


Charu.
There is another suggestion in this forum
http://forums.iis.net/t/1066272.aspx

Author

Commented:
@Aurora27:
I just found that exact same solution about 5 minutes ago.  I'm looking into it as well.  Please let me know how your results turn out.

@RedKelvin:
That's another one that I already found.  It basically ended up the same way as the rest of the solutions I found.

Thanks again!

Author

Commented:
@Aurora27:
I just tried that solution, but it gave me the same error.  It looks like IIS stopping the postback before it even gets to any of the stream processing.  It's checking the size of the file before any code is executed.

Somehow I still need to get IIS7 to say it's ok to upload a large file.

By the way, I just realized that I get the same error even if I use the upload control to browse for a large file and then I click on the cancel button.  Any postback at all while a large file is selected causes the error to occur.  :(

I'll have to try some more tomorrow.

Thanks!

Commented:
Yeah..me too..the connection resets and it does not allow within the current connection. I knew there is some way of doing it . Did it long back once. Will figure it out in the night or tommorrow :)

Anyway, that was challenging.

Commented:
Sure, you're welcome ;)
Hey,

When sending large files to an asp page, it is always best to send it in multiple parts. Here are two examples of how this might be solved:

http://www.codeproject.com/asp/aspupl.asp
http://www.codeproject.com/useritems/UpldFileToDiskProgressBar.asp

Kjetil

Commented:
Sending via FTP is the solution that works for me. Or again, multiple files is an option. I havent looked into that.

Author

Commented:
@Aurora:
I played with the solution you posted last night @9:20 a little more, and I think I might actually be able to get it to work.  

I just need to finish it up tonight.  I'll let you know how it turns out.

Thanks to everyone for your help!

Author

Commented:
@Aurora27:
Your link seemed to ultimately solved my problem.  I was able to get my page to upload a 66MB file!

@RedKelvin:
Although I had already implemented your solution, I tried removing it, and my application immediately failed again.

Thanks again for your time!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial