Ajax post request have more than 4 mb file - ajax

I am developing an MVC 4 application.I am sending ajax post request to a controller action.When the post data is more than 4MB the requist to action is failing.What is the solution for this?

You need to change two configuration parameters (value is in KB)
In Web.Config
<configuration>
<system.web>
<httpRuntime maxRequestLength="8192" />
</system.web>
</configuration>
In IIS
Update your 'Maximum allowed content length' setting, as described here : http://ajaxuploader.com/large-file-upload-iis-asp-net.htm

You could try extending the size of one of these properties..
<system.web>
<httpRuntime maxRequestLength="x" />
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="x" ></requestLimits>
Set, x to the size limit you want. Read this post for help.

Related

.Net Core 2.1 Error 413 on multipart/form-data POST only on IIS not IIS Express

I'm hitting a problem with multipart/form-data POST uploads on IIS. My client is an Angular SPA and my backend is on .Net Core 2.1 (I know it's old).
The backend project is published as Self-Contained win-x64. I'm not sure how it's configured exactly on IIS / Kestrel but the IIS App runs under a specific Application Pool (No managed Code / Integrated). My web.config looks like this:
<configuration>
<location path="." inheritInChildApplications="false">
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\my.app.exe" stdoutLogEnabled="false" stdoutLogFile=".\log\path" />
</system.webServer>
</location>
</configuration>
In my development environment instead I'm using IIS Expres.
Now I added a multipart/form-data upload, sending form data together with a blob/image. This worked out of the box in development settings. However when I publish to staging environment with real IIS and the above web.config, I always get 413 Request entity too large.
My controller looks like this:
[HttpPost]
[DisableRequestSizeLimit]
[RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue, ValueLengthLimit = int.MaxValue)]
[RequestSizeLimit(int.MaxValue)]
[Route("my/route")]
public ActionResult MyHandler()
I also added limits for Kestrel in Program.cs:
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 104857600; // 100MB
}
)
And to make the weirdness complete the 413 in staging environment only happens in Firefox. I have no idea what else I can do. I also cleared cache in firefox.
After longer search I finally found the necessary setting in IIS to make this work in Firefox. And it has indeed be mentioned in a few sources as the 'last option'. For me it was necessary in this case.
In 'IIS Manager' I selected the backend application and opened 'Configuration Editor'
system.webServer/serverRuntime -> uploadReadAheadSize=2147483647
That maked it work.

Asp.Net Core RC2 timeout on upload

Working on file upload with somewhat large payload (800 MB) and server is timing out.
Using asp.net core RC2, mvc6 and Kestrel server on Windows (7 and 10) and cannot find where to set the session timeout.
I'm going nuts that I can't find it searching the web. How do you set the timeout?
I just ran into a similar problem and found out that apparently IISExpress (at least when used from Visual Studio) has a default 2 minute connection timeout after which it responds with 502 bad gateway. I could fix the problem by adding the attribute "connectionTimeout" with a suitable value to the element "webLimits" in .vs\config\applicationhost.config:
<webLimits connectionTimeout="00:10:00" />
Here is some more info on the webLimits element: https://www.iis.net/configreference/system.applicationhost/weblimits
Update after upgrading to ASP.NET Core 1.0: There is a "requestTimeout" attribute on the aspNetCore element in the web.config. This attribute also has a default value of 2 minutes.
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore
processPath="%LAUNCHER_PATH%"
arguments="%LAUNCHER_ARGS%"
forwardWindowsAuthToken="false"
stdoutLogEnabled="false"
requestTimeout="00:10:00" /> <!-- <== -->
</system.webServer>
</configuration>
For more attributes on aspNetCore see:
https://learn.microsoft.com/en-us/aspnet/core/hosting/aspnet-core-module

WebApi 2 Maximum request length exceeded

Does anyone know if there is a way of catching this error?
Essentially I'm trying to implement some functionality to allow a user to upload a file from a webpage to a webapi controller.
This works fine, but if the file size exceeds the maximum size specified in the web.config the server returns a 404 error.
I want to be able to intercept this and return a 500 error along with message which can be consumed by the client.
I can't work out where to do this in WebApi as the Application_Error method I've implemented in Global.asax is never hit and it seems like IIS is not passing this through to the WebApi application.
Try to set IIS to accept 2GB requests(in Bytes).
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" /> // 2GB
</requestFiltering>
</security>
</system.webServer>
And set reasonable request size for ASP.NET app(in kiloBytes).
<system.web>
<httpRuntime maxRequestLength="4096" /> // 4MB (default)
</system.web>
Now IIS should let requests less than 2GB pass to your app, but app will jump into Application_Error reaching 4MB request size. There you can manage what you want to return.
Anyway, requests greater than 2GB will always return 404.13 by IIS.
Related links:
Dealing with large files in ASP.NET Web API
How it looks like on my server:
<system.web>
<httpRuntime targetFramework="4.6.1" maxRequestLength="16240" />
</system.web>

Getting No 'Access-Control-Allow-Origin' when sending large JSON via AJAX

I'm working on a web page that calls a REST webservice via ajax to get and insert data.
The problem is that we need to send a base64 image in a JSON. You know, the base64 image is the imaged converted to that large text: base64/fjhd7879djkdadys7d9adsdkjasjdshk...
When we try with a 1 KB image, it works.
But with a bigger file(55kb), it doesn't.
So I assume it has something to do with the maxRequest, but the error says that is No 'Access-Control-Allow-Origin'. But we havent fount any way to configure it. Please help.
By default browsers block json requests from other domains other than the page unless the json request has the Access-Control-Allow-Origin header, so you'll need to add that header to your json requests on that service or use the same domain for both.
More info here: https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
You can try setting the maxJsonLength to it's maximum value in the web.config file.
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647"/>
</webServices>
</scripting>
</system.web.extensions>
I know this is an old post, but for anyone who still might be having this problem, I solved it by adding two settings to Web.config as described here: https://west-wind.com/webconnection/docs/_4lp0zgm9d.htm
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647"></requestLimits>
</requestFiltering>
</security>
<!--snip-->
</system.webServer>
and
<system.web>
<httpRuntime maxRequestLength="2147483647" />
<!--snip-->
</system.web>

JQuery Ajax File Upload Fail on Large Files

I currently have a ASP.Net MVC web application that needs to upload large files using ajax. I am currently using this jQuery plugin - http://valums.com/ajax-upload/. I have also used this plugin - http://jquery.malsup.com but get the same result.
The issue that I am having for large file is that the iframe that gets generated to in order for the request to be asynchronous is not loading in time.
It always seems to point to this code:
var doc = iframe.contentDocument ? iframe.contentDocument : iframe.contentWindow.document, response;
For smaller files the script works great but for larger files the iframe nevers seems to get initialized properly.
This has been driving me crazy. Can someone please HELP.
thanks in advance
You might need to increase the maximum allowed request size on the server as well as the execution timeout of the request using the <httpRuntime> section in your web.config
<system.web>
<httpRuntime
maxRequestLength="size in kbytes"
executionTimeout="seconds"
/>
...
</system.web>
And if you are deploying your application in IIS 7.0+ you might also need to increase the maximum allowed request size using the <requestLimits> node of the <system.webServer> section:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="size in bytes" />
</requestFiltering>
</security>
...
</system.webServer>

Resources