I'm having the problem with sending a file as a byte array json string to the server. When the file is relatively small: up to 2MB
or so, then it works fine, but if the file is like 4MB
then the request throws error (it doesnt even reach the controller in the backend).
Error:
XMLHttpRequest cannot load http://localhost:61416/api/organisationdocuments/.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:51080' is therefore not allowed access.
The response had HTTP status code 404.
In the startup.cs
I have
// Add CORS support.
services.AddCors(options =>
{
options.AddPolicy("AAPolicy", policyBuilder =>
policyBuilder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
);
});
In the front-end I use angularjs
. The method looks like this:
this.addFile = function (file) {
return $http.post(fileApi, file);
};
I debuged it on the front and it looks alright, except the string with the byte array is so big it hangs my browser sometimes. So As I mentioned, it works for smaller files, only occurs for the bigger ones. It obviously has to do something with the weight of the file.
I tried to debug back-end, but it doesnt even reach the controller, so there is no way. Any ideas? Thanks a lot!
Edit:
My web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime maxRequestLength="10000000" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="10000000" />
</requestFiltering>
</security>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600" />
</system.webServer>
</configuration>