Uploading Large File in C# & ASP.NET MVC - c#

I am trying to upload a file using C# and ASP.NET MVC, and I am getting this error:
HTTP Error 413.1 - Request Entity Too Large
The request filtering module is configured to deny a request that exceeds the request content length.
This is how I configure my web.config:
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.7.2"/>
<httpRuntime targetFramework="4.7.2" executionTimeout="3600" maxRequestLength="104857600" enable="true"/>
</system.web>

For IIS7 and above, you also need to add the lines below:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>

Related

.NET 4.6.1 and IIS7 - Cannot upload large files from WebAPI2 endpoints

I am trying to upload files using my .NET application. I cannot upload large files and it responds with 413 - Request Entity Too Large.
I tried solutions that suggested changing maxRequestLength and maxAllowedContentLength in web.config. Also changed the uploadReadAhead setting in IIS. I still am unable to upload the files.
The project has two web configs. Parent directory web config has the following settings:
<system.web>
...other lines
<compilation targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" maxRequestLength="2147483647" executionTimeout="999999" />
<customErrors mode="Off" />
</system.web>
The web config in the inner Portal directory has:
<system.web>
...other lines
<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" executionTimeout="999999" useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" />
</system.web>
<system.webServer>
...other lines
<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" executionTimeout="999999" useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" />
</system.webServer>
How do I fix this ?
Thanks.
Hum, that should be fine. On the other hand, seems to me that adopting some kind of nice up-loading library that up-loads in chunks would be better. This tends to "less freeze up" the user interface and also tends to not freeze up the web server either.
I mean, for a user to up-load a big file, then they are going to be stuck watching the screen - nothing occuring. With a nice up-loader library, then only small chunks are sent up, you get a progess bar, and you have un-limited up-load file sizes.
However, you could try in the main web.config,
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2048000000"/>
</requestFiltering>
</security>
</system.webServer>
So, you could try adding above under system.webServer

ASP.NET Core web.config requestFiltering not overriding applicationhost.config

I'm trying to upload large files to an API controller action in my ASP.NET Core MVC 2.1 application. To that end I've been trying to figure out how to allow this through IIS Express which is how I'm running the application through Visual Studio. As suggested, this should be possible by adding a web.config file to the project root with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<!-- Configuration for IIS integration -->
<configuration>
<system.webServer>
<security>
<requestFiltering>
<!-- 2 GB -->
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
However, this doesn't have any effect as the application just returns HTTP Error 404.13 - Not Found, indicating the request is too large. It seems as if those settings are locked by the IIS so the web.config isn't overriding them. Yes, I'm also using attributes such as [DisableFormValueModelBinding] and [DisableRequestSizeLimit] on the controller action.
Instead I found that it works by adding the same configuration to the site in the applicationhost.config in the \.vs\config folder:
<location path="MySite">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600" requestTimeout="23:00:00" />
<httpCompression>
<dynamicTypes>
<add mimeType="text/event-stream" enabled="false" />
</dynamicTypes>
</httpCompression>
<!-- Everything above this point is auto-generated -->
<security>
<requestFiltering>
<!-- 2 GB -->
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
</location>
This file, however, is not tracked in GIT and it doesn't seem like a good solution to add it to GIT either.
Is there some security reason or other for why the web.config seemingly is not allowed to override the applicationhost.config? Or is there a solution that I just haven't been able to figure out?
I had a similar issue, I added a web.config with this
<configuration>
<system.webServer>
<security>
<requestFiltering>
<!-- This will handle requests up to 700MB (CD700) -->
<requestLimits maxAllowedContentLength="737280000" />
</requestFiltering>
</security>
</system.webServer>][1]][1]
</configuration>
posted too soon. The above solution worked for iis express server but did not for docker. Then I updated the entry
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 100000000; //100MB
});
Then decorate controllers with [RequestSizeLimit(100_000_000)]
Those solutions solved locally and in prod for me.

AsyncFileUpload Content Security Policy Directive

I am trying to upload a file to an application i have built using the AsyncFileUpload part of the AjaxToolKit. The file is a 50mb ZIP file, when uploading i receive the following popup:
When i click OK i get the following box
If i then go into Developer tools i get the following error message in the console tab of chrome
The value for Content Security Policy directive 'object-src' contains an invalid character
Any help would be appreciated
It looks like you need to modify your Web.config like in this answer:
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
or for IIS 7 or later:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>

How to upload file with the 10GB+ size in ASP.NET C#

I am trying to upload file with size more than 10GB+ and there is multiple files that i want to upload at the server.
I made some changes in Web.config to upload large files.
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime executionTimeout="6000000" maxRequestLength="2147483647"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
But it only support the file size up to 2GB. I do too much research but I can not get anything that help me to upload 10GB+ file size.
I read some article that said that the maximum file size limit is 2GB
Maximum value of maxRequestLength?
IIS 7 httpruntime maxRequestLength limit of 2097151
https://blogs.msdn.microsoft.com/prashant_upadhyay/2011/07/12/large-file-upload-issue-in-asp-net/
I found some hacks that I slice the file at the client side (browser) and upload that all the slice at the server and after that i merge all that slice to single file.
But this may be wrong idea to do that, If some slice of file is failed to upload or missed so file may be corrupted.
I don't want to implement the Slice and Upload and Merge file technique to upload large file.
There is any another way to do the Upload Larger files (10GB+ size) with the ASP.NET and C#.
Thanks.
only use this
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime executionTimeout="6000000" maxRequestLength="10485760"/>
</system.web>
remove below code from web.config
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
and 10gb = 10485760 kb

Uploading large file using MVC Web API Method from Windows phone 8 app not working

I am trying to upload file from my one of Windows phone 8 application. We are using MVC4 web API which is working perfectly fine until and unless file size is less than 5 MB. Any file with more than 5 MB is giving me 404(Not found) in response.
I think from API side there is no problem as I am able to upload the same file using Fiddler with no error.
I am using HttpClient to post request to service.
Any help will be highly appreciated.
Vinod
Try increasing the MaxRequestSize in the web.config for the mvc site
<configuration>
<system.web>
<httpRuntime maxRequestLength="10240" />
</system.web>
</configuration>
In IIS 7+ try this
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
</requestFiltering>
</security>
</system.webServer>
Just make these changes in web.config file:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
...

Categories