-1

I am trying to upload up to 2GB of data using a HttpClient. The data is sent through the request body into an aspx page where it is read (horrible, I know but I cannot change this.)

The data is placed in a MultipartFormDataContent and posted like this:

var apiRequest = new MultipartFormDataContent();

apiRequest.Add(new StreamContent(file), fileName, fileName);

apiRequest.Headers.ContentDisposition = 
    new ContentDispositionHeaderValue("form-data") { Name = fileName, FileName = fileName };

HttpClient client = new HttpClient();
client.Timeout = TimeSpan.FromMinutes(30);

HttpResponseMessage response = null;

try
{
    response = client.PostAsync(apiEndPoint, form).Result;
    response.EnsureSuccessStatusCode();
    string responseBody = response.Content.ReadAsStringAsync().Result;
}
catch (HttpRequestException e)
{
    log.LogError($"logging here");
}

Things I have tried :

-HttpClient http version 1.0 instead of default

-HttpClient MaxRequestContentBufferSize

-web.config maxAllowedContentLength

-web.config AspMaxRequestEntityAllowed

-web.config maxRequestLength

Currently, the files get added to the httpClient correctly but I cannot get them to post to the web app. I got up to 900MB through but anything over that simply redirects to the main page and I get HTML from the web app in the response body.

Thanks in advance!

Rocco_STACK
  • 16
  • 1
  • 1
  • 6
  • So when it up to 900 MB or more larger, page just redirects to main page but not show any information in browser console? Or nothing in your custom log error? Have you tried to set multipart/form-data in MultipartFormDataContent? – Bruce Zhang Jul 28 '21 at 05:17
  • That is correct, it redirects to main page without information and without the custom log. I have just tried setting multipart/form-data but to no avail. – Rocco_STACK Jul 28 '21 at 12:38

1 Answers1

0

After a lot of hair pulling we found the solution by looking at the IIS logs.

The logs revealed that the Microsoft URLScan tool was blocking the requests. When the request body was not approved by the scan, IIS would redirect you straight to the main page with no error.

You have to configure a max request length in the urlscan.ini file. More info here: https://ajaxuploader.com/large-file-upload-iis-debug.htm

The file is located at C:\WINDOWS\system32\inetsrv\urlscan

Rocco_STACK
  • 16
  • 1
  • 1
  • 6