I have a JavaScript application which is posting files to .NET Core 3 Web API.
Web API project works locally on IIS Express.
Files below 30 MB are working fine, but large files does not get through.
Here I tried;
1- Update %userprofile%\my documents\iisexpress\config\applicationhost.config file with new maxAllowedContentLength value.
2- Add RequestSizeLimit attribute to Controller Action.
Is there anything else I am missing here?
I had the same problem (since .NET Core 3), and found a workaround first, then a proper solution.
Workaround: in your web.config file, use "AspNetCoreModule" instead of "AspNetCoreModuleV2", but you no longer benefit from the advantages of the new module.
A solution: add this to your startup.cs file
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = int.MaxValue; // or your desired value
});
I found this info here: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1#application-configuration. IIS options > In-process hosting model, then attribute "MaxRequestBodySize". For this to work, you still need to have your web.config configured with something like this:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" /> //or your desired value
</requestFiltering>
</security>
Hope it helps!
For NetCore 3.1
1° you can add the attributes :
[RequestSizeLimit(300000000)] // for 300Mb files
[RequestFormLimits(MultipartBodyLengthLimit = 300000000)]
2° in web config add the follow line:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="300000000"
</requestFiltering>
</security>
Related
How to provide maxAllowedContentLength without using web.config
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
According to the asp.net core document, you could find we could try to set MaxRequestBodySize if you aren't host the application on IIS.
If you want to host the application on the IIS, you could only set the maxAllowedContentLength in web.config, since the maxAllowedContentLength is happened before the MaxRequestBodySize.
More details, you could refer to below description.
MaxRequestBodySize is used to get or set the max request body size for the HttpRequest.
Note that IIS itself has the limit maxAllowedContentLength which will be processed before the MaxRequestBodySize set in the IISServerOptions. Changing the MaxRequestBodySize won't affect the maxAllowedContentLength. To increase maxAllowedContentLength, add an entry in the web.config to set maxAllowedContentLength to a higher value. For more details, see Configuration.
We have an .net core Web application which simply hosts files for some of our client applications updates.
We decided to add Application insights in one of these client applications, and the file ApplicationInsights.config is a part of update.
The request to https://server/path/to/update/ApplicationInsights.config throws 404 error.
So far I’ve tried :
Add “.config” extension in static files definition on the startup : no effect (This worked for .exe and .dll)
Enable folder browsing for this folder, still no effect
It seems to be related to some out-of-box requests filtering.
The question is :
How do I disable all download restriction on a specific folder (Best)
OR
How do I disable ALL filtering for *.config files
Thank you in advance
That's because the default FileExtensionContentTypeProvider doesn't provide a mapping for *.config files.
To make it serve *.config files, simply create your own ContentTypeProvider, or add mapping for *.config :
var myContentTypeProvider= new FileExtensionContentTypeProvider();
myContentTypeProvider.Mappings.Add(".config","text/plain");
app.UseStaticFiles(new StaticFileOptions{
RequestPath = "/path/to/update",
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(),"path/to/update"),
ExclusionFilters.None
),
ContentTypeProvider = myContentTypeProvider,
});
[Update]
After a discussion, the following Web.Config ( by OP) works:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions>
<remove fileExtension=".config" />
<add fileExtension=".config" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
</configuration>
I want to download a file in mvc That size is 200mb
The following error occurs :
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown
my code is :
public FileResult Download(string name)
{
var videoFilePath = HostingEnvironment.MapPath("~/VideoFile/" + name + ".mp4");
//The header information
var file = new FileInfo(videoFilePath);
//Check the file exist, it will be written into the response
if (file.Exists)
{
return File(videoFilePath, System.Net.Mime.MediaTypeNames.Application.Octet,
file.Name);
}
return null;
}
The error does not occur when the file size is small
why ?
Recently I kept getting System.OutOfMemoryException exception while working on a web application with Visual Studio 2013.
The full exception message title was as follow:
System.OutOfMemoryException Exception of type 'System.OutOfMemoryException' was thrown.
To resolve this issue, I had to restart Visual Studio or go to the Windows Task Manager and terminate IIS Express process.
This error could happen due to a variety of reasons related to memory consumption of the application. Looking at my local machine memory, there was always enought memory available! Then what was the cause?
Turns out, Visual Studio uses IIS Exoress 32 bit version by default whereas 64 bit version is available right out there! So as a work around you go to the following path and make Visual studio to use 64 bit version of IISExpress.
Tools | Options | Projects and solutions | Web Projects => Use 64 bit version of IIS Express for websites and projects
Apparently behind the scene Visual Studio changes a flag in windows registry which the key could be found at this path.
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\WebProjects --> Use64BitIISExpress
I believe your MVC 4 project needs to be updated to support 200 mb files and also, IIS needs to be updated to support 200 mb files.
To change it at the IIS level, I think adding this to your web.config file should work. (untested)
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="209715200"/>
</requestFiltering>
</security>
</system.webServer>
And to pull from another SO post, add the following to your web.config file
<location path="File">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="4096" />
</system.web>
</location>
<location path="Picture">
<system.web>
<httpRuntime executionTimeout="60" maxRequestLength="1024" />
</system.web>
</location>
Where "File" and "Picture" are your controller names.
On that link, the accepted answer also addresses upload timeouts, which might be a problem as well for a 200 mb file.
i did like i saw in many threads, like going to Internet Information Server Manager then to the site then Request Filtering and then on the right Edit Feature Settings... then i set the Maximum allowed content length to 1000000000, and restart the web site, but it didn't work, the second method i tried is that i have added the following:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1000000000" />
</requestFiltering>
</security>
</system.webServer>
in the Web.config file in the web site and i restarted the web site,but still getting the error Maximum request length exceeded.
so is there any solution or any other step i missed ?
I have been testing out the new WCF fileless activation stuff in .net 4 that allows you to use config rather than having a physical svc file.
The relevant part of my web.config looks like this:
<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="Service1.svc" service="WcfService1.Service1" factory="WcfService1.UnityServiceHostFactory" />
</serviceActivations>
</serviceHostingEnvironment>
This runs ok but if I add any breakpoints, they do not get hit. When using svc files, they have debug="true" in the markup but I do not know how to allow this when doing it through config.
Any ideas?
Oops. It seems as though I was mistaken. After being called on to something else for a while, I have revisited this code and it appears to be working normally. The debug flag in normal svc files doesn't actual do anything.