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

0

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.

c#
asp.net
http
iis-7
asked on Stack Overflow Oct 17, 2016 by J.Small • edited Oct 17, 2016 by J.Small

2 Answers

0

Maybe you could use a function with the form of the next one to reach your objetive, I've tested it and it doesn't stop receving files, let me know if this works for you:

public Stream Downloadfile(string filename)
        {
            WebOperationContext.Current.OutgoingResponse.Headers["Content-Disposition"] = "attachment; filename=" + filename;
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream";
            return File.OpenRead(filename);
        }
answered on Stack Overflow Oct 18, 2016 by Ronny -Barrera
0

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.

answered on Stack Overflow Oct 21, 2016 by J.Small

User contributions licensed under CC BY-SA 3.0