Try to use File.SAVEAS but get 404 error, because the size is big
I'm using asp:fileupload control to upload my Picture files. So the user click on browse and select the file and click on upload and in event handler of upload button there is FileUpload.PostedFile.SaveAs () etc.
Everything works fine. Accept when for big file size. e.g. I've got a file (jpg) 5.5 MB. When I try to upload this file I get an the error below.
The strange thing is I the button upload file eventhandler I check the file size. If (intFileesize < intFileSizeLimit) etc.
But the strange thig is I remove all开发者_开发百科 the code in Upload eventhandler for testing/debugging and I still get the error below. So the error occurs outside the Button handler. I mean the error cause is not by Fileupload.SAveAs etc.... So the question is how can I avoid this. I mean I have built restriction of 1 mb, but This code is not reached.
I don't have any problems with small sizes e.g. I could upload 400 kb w/o problem.
So the question is what is the cause for the big file size how can I solve this?
Other question is: Is there a tool or whatever to crop the filesize and upload? I mean even if they upload 6 mb picture, I should crop that to 50kb or whatever during upload. How to aproach this? maybe a 3rd party freeware?
ERROR I get after 2-3 seconds
Oops! This page appears broken. HTTP 404 - File not found.
see maxRequestLength
in http://msdn.microsoft.com/en-us/library/e1f13641.aspx
The default request size is likely being reached. By default I believe ASP.NET supports a 4MB request size limit. You can change this in your config:
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
The above example changes the request size to 20MB. The thing to take into consideration is that HTTP was never really designed to handle large file uploads. You may want to consider using an alternative, such as a Flash upload control...
UPDATE
For IIS7 you may need to update the configuration in the system.webServer
section:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="20480" />
IIS uses the same configuration system as ASP.NET, but because it may not be an ASP.NET handler being called, it has an additional setting for other content requests.
Since you already have maxRequestLength
set in the <httpRuntime>
tag in web.config, it looks like you are hitting the IIS7 request filter.
Try adding this to your web.config:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="33554432"/>
</requestFiltering>
</security>
Depending on how your server is set up, you may also need to change the IIS configuration to allow you to set up request filtering at the application level rather than the machine level. Edit %windir%\system32\inetsrv\config\applicationHost.config
and change:
<section name="requestFiltering" overrideModeDefault="Deny" />
To:
<section name="requestFiltering" overrideModeDefault="Allow" />
精彩评论