J.Small J.Small - 1 year ago 68
ASP.NET (C#) Question

Making Second HTTP Request (before first ends) closes connection to the first

I have a website that allows users to download files via clicking href links that will call an HTTP GET request and return the file (will prompt user in IE and auto-download in chrome)

public async Task<IActionResult> DownloadFile(DocumentFile file){
fileName = DocumentTask.RetrieveFiles(new string[1] { file.FileID }, file.Facility, UserData.Access).SingleOrDefault();
if (System.IO.File.Exists(fileName))
FileInfo info = new FileInfo(fileName);
return File(System.IO.File.ReadAllBytes(fileName), FileUtility.GetContentType(fileName), info.Name);

When a user clicks a download link:

<a href="/File/DownloadFile?FileUID=1111&amp;Facility=TestFacility&amp;Name=TestFile.pdf"><i class="file pdf outline icon"></i>TestFile.pdf</a>

and than immediately after clicks another download link (before the first download link has returned a response) it appears the client closes the connection to the first request. It will give this error:

The remote host closed the connection. The error code is 0x800703E3.

This error gets thrown when the server attempts to return the file back to the user, but it can't because the connection has been closed.

Using the Chrome developer tools, I can see both requests getting queued however as soon as the second request is sent, it cancels the first request (closing the connection).

Chrome Developer Request Cancelled

Right now I have disabled the user from clicking another download link until the previous request has returned however I would like to know if there is a more elegant solution to allow for multiple requests to be sent and waited for?

(I have tested this in Chrome and IE 11 and both cancel the previous request sent)

Thanks in advance.

Answer Source

I was unable to find an answer to my solution. However I was able to change the way my links worked. By changing the links target="_blank" it will open up a new page and close when the file has begun downloading. This stops the user from selecting a second link until the other returns, but also if they use the middle mouse button to open the link but not change tab focus, this stops the error from occurring. I think multiple requests from the same tab was the issue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download