I keep getting a SystemOutOfMemoryException when processing large files like 1.6GB in size. I was just wondering if my configuration in web.config is correct. Below are the lines of code I modified to support large files that is more than 1GB in size
<httpRuntime requestValidationMode="2.0" enableVersionHeader="false" maxRequestLength="457286400" executionTimeout="3600" targetFramework="4.5" fcnMode="Single" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="3294967295" />
</requestFiltering>
</security>
I'm not sure if this is correct. I also changed the IIS server to run in x64 via Tools-> Options-> Project and Solutions-> Web Projects -> "Use the 65bit version of IIS"
I'm not sure what I'm missing but I keep getting the system out of memory exception even though I already increased the memory size
UPDATE:
I'm processing a large files like .mp4 files or just anytype of file regardless of type as long as the client requires it.
Also I'm not uploading the file using a frontend. What we do is upload the large file via Filezilla and if the file is uploaded to the server we use the Umbraco MediaService to process this file to have an entry in the Media Page. We are also using Hangfire to trigger our background service to process the MediaService
Accepting large files like this, is not a best practice. Eg this gives the possibility to perform a Ddos attack. Also you will need a lot of memory as the file will be handled in memory before persisting it to disk, hence the issue you have with memory.
The better solution would be to chunk them with javascript and send over small packets, and the stitch them back together server side. There is a pretty good explanation on how to build this yourselves : https://www.dotnetcurry.com/aspnet-mvc/893/upload-big-files-aspnet-mvc-azure-storage
(depending on how you handle your sessions, adding it to the session might not resolve your memory issue. I guess you'll need to save it to disk)
Unrelated to the memroy exception, but make sure you wrap this in a <location path="xxx/yyy"> your web.config stuff </location> so that only this URL will accept large files.
Managed to solve this issue by adding a 2nd and 3rd parameter in my Umbraco MediaService. Initially I was using Service.MediaService.Save(iMediaFile) but it seems that when using large file it needed to know who uploaded the file hence it needs the 2nd parameter which is the user_id and I added the third parameter to suppress any error message. As I was encountering an out of memory exception where in fact the error was I didn't pass the user_id in the second paramter. Hence my new code became Service.MediaService.Save(iMediaFile, user_id, false)
Again the solution was not really a configuration as my configuration was enough to process the file. The error was due to missing 2nd parameter
Related
I have a website running on IIS 7.5 which I can only access using FTP. (So I won't be able to use IIS Manager.)
I want to reorganise the URL structure, so I've modified the Global.asax code to look for the old URLs and Response.Redirect them to their new location. This works great for some of the URLs but not all.
With some experimentation, I found that when the old URL has a dot (eg, http://example.com/hello.html) then my global.asax code doesn't run. If I remove the file extension part of the URL, the global.asax code runs fine.
Those URLs with .html etc on the end are already out there and I can't change them now.
What do I need to do please?
What's happening is that IIS thinks your request for "/hello.html" is a static file and tries to serve it up directly without handing it off to your ASP.ENT application (before it gets to the routing in your Globals.asax file).
To change this behavior, you need to tell IIS to send these requests to your ASP.NET app instead of handling them itself. You can do this in your web.config file:
<system.webServer>
<handlers>
<add name = "LetMeHandleMyOwnStaticContent" path ="/*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersion4.0"/>
</handlers>
</system.webServer>
Note, this will make you handle ALL of the static files (be prepared to handle the .js files, .css files, .html files, .png files, etc.) through your app. You can manipulate the path and verb to narrow down what you want to serve through your app. You can add multiple filters by repeating the "add" element (just use a unique name for each path).
When attempting to upload a file of 35 megs, the website hangs.
I have set a break point on the server side before the File.SaveAs(path) command is even called.
I do a check on the server side to make sure the file is less than 20 megs, but it doesn't even reach this point. The web page just continues to load until I get a connection was reset error.
Increase maxAllowedContentLength in web.config
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576000" />
</requestFiltering>
</security>
</system.webServer>
In Web.config in system.web :
<httpRuntime maxRequestLength="100000"/>
100000kb =100 MB
If you upload the file with simple HTTP-POST you need to wait for the whole file to be uploaded. You can't abort the upload earlier in the controller, only with web.config as cosset's answer suggests.
You could use maybe Flash to check the file size on the client already, don't know details about that though
Could this be a good chance to use async as shown here?
There is also an excellent article on async and await here.
Web.Config issues aside, a file that big is going to take some time. I would try not to block the current thread with such an action.
Another question from me. This wont be an easy one!
I'm having issues with handling a simple upload.
Pre Requirements to test with:
- No Flash (hijacking)
- Basic upload field usage + form to post
- Max file size is 20MB (web.config maxrequestlength)
- I'm running the web site with the build in IIS development tool in visual studio (i think)
- I'm using a MVC web project
Question: Is it possible to show a nice error message to the user when a file is larger than 20MB? (Without getting the whole file to the server first)
These links helped me the most:
http://www.telerik.com/community/forums/aspnet/upload/maximum-request-length-exceeded.aspx
ASP.NET MVC: Handling upload exceeding maxRequestLength
http://forums.whirlpool.net.au/archive/809909
http://forums.asp.net/t/1106579.aspx/1
Catching "Maximum request length exceeded"
But still i haven't been able to fix the issue. Atm i use the code of the accepted answer of the last link (Catching "Maximum request length exceeded"), but my code crashes when i run the code line below:
this.Server.Transfer("~/error/UploadTooLarge.aspx");
Error message: Error executing child request for ~/error/UploadTooLarge.aspx.
I think i get this message because i'm using VS.NET's build in web server (see: http://forums.asp.net/t/1106579.aspx/1 last post of that page).
I'm affraid i made the whole question a bit hard to read. In short:
How can i show a neat error message when i uploaded file is too large (using S.NET's build in web server)?
If you don't want to send to whole file to the server first, then your only option would be javascript.
The FileReader object would solve that for you
https://developer.mozilla.org/en-US/docs/DOM/FileReader
Problem being it won't work on older browsers.
Now, if older browsers are not a problem for you then you should find plenty of tutorials showing you how to use the FileReader object. With it you can do asynchronous uploads so you even add a nice progress bar considering is fairly large file.
Background
I am developing an ASP.Net server side control that needs to talk to an ASMX web service. The server side control uses a WebClient object to talk to the web service, since it needs to be reused often in various application, and to make it easier on the developers, they are not required to create a service reference to the web service.
Implementation
During the use of the control, it is requires the sending of a serialised object to the web service. The object is serialised using the XmlSerializer and the resulting XML string is then compressed using the chilkat compression library. The web service call for the control looks as follows:
webClient.UploadStringAsync(new Uri(serviceHost + serviceMethod), "POST", sendData)
The content of sendData (string) is compressedResponse={CompressedData}.
The web service has a method defined as follows to receive the data and then decompress the string value using the chilkat library before de-serialising the object using the XmlSerializer.
public void SaveResponse(string compressedResponse)
The communication between the control and the service is working. Initially there were no settings or binding defined in the web.config for any of the above. After initial searching I did add
<httpRuntime maxRequestLength="20480"/>
to both the client and server web.config files. This has made no difference.
Problem
Compressed or uncompressed the data being posted to the web service in the sendData variable is to big for a normal POST request, and is corrupted. This is confirmed when checking the last few characters of the string before and after it being posted to the server in compressed format, and uncompressed, the Xml document is missing the last root tag when checking in the debugger. The string can't be decompressed and therefore the service call fails every time.
How do I increase the POST size for the WebClient request to ensure that the full string is received by the server?
I have looked at the various option on Google, but none are giving me a good enough sample of where to make the changes, or samples of what the changes need to look like. I am completely lost as to whether the change needs to be made on the server or the consuming website, and since there are no binding defined for this, how to create a binding in the web.config for an ASMX HTTP service call.
I believe you must be hitting ASP.NET max request length limit. That you can modify via config file such as:
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
maxRequestLength value is in KB, so above setting would allow 20 MB. You can also apply the setting only to selected URLs using location tag e.g.
<location path="yourservice.asmx">
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
</location>
There seems to be no way to change the POST size for a ASMX Web Service when only HttpPost is enabled.
The solution in the end was to switch the service to running HttpSoap and create a service reference to the assembly containing the control. Once done the binding is created using code in the control once the endpoint is set via a property.
Ok, I'm a real newbie at the ASP stuff... I have two related questions:
What are my options for controls I can dynamically add to my webpart to allow a user to upload large files >100MB to the server?
What are my options for controls to trigger a download of a large file in a web browser with a "Save As" dialog box, so that the server can generate a file and send it to the user?
I've seen examples for FileUpload controls, HttpRequest/HttpResponse controls, FileWebRequest controls... its never clear if the examples are intended for windows apps scraping off websites, or client scripts that are tied to buttons, or serverside code that acts on a postback. I guess I'm looking for the latter... something I could write in the server code to trigger the interaction.
If anyone knows where I can find a clear tutorial, that would also be appriciated.
By default, ASP.Net restricts the file uploaded to the server to be 4 MB. We can increase this setting in Web.Config through the tag.
The below configuration setting is configured for all default values.
<httpRuntime
executionTimeout="110"
maxRequestLength="4096"
requestLengthDiskThreshold="80"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="5000"
enableKernelOutputCache="true"
enableVersionHeader="true"
requireRootedSaveAsPath="true"
enable="true"
shutdownTimeout="90"
delayNotificationTimeout="5"
waitChangeNotification="0"
maxWaitChangeNotification="0"
enableHeaderChecking="true"
sendCacheControlHeader="true"
apartmentThreading="false" />
To increase the default upload size, we need to increase the value of maxRequestLength property to whatever we want in KB. Default is 4096 KB(4MB).
To upload 100 MB, set
maxRequestLength="102400"
Copy the above configuration inside tag in Web.Config.
this is the link http://programming.top54u.com/post/ASP-Net-FileUpload-Size-Limit-Example.aspx
ASP.NET does have a FileUpload control. For files of that size however, I recommend that you look at an alternative solution, like FTP.